(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

socket_get_optionPega opções de socket para o socket


socket_get_option(resource $socket, int $level, int $optname): mixed

Esta função é EXPERIMENTAL. O comportamento, seu nome e documentação podem mudar sem aviso em futuras versões do PHP. Utilize por sua própria conta e risco.


Esta função não está documentada; somente a lista de argumentos está disponível.


Essa função é para ser usada chamando socket_getopt() primeiramente para PHP 4.3.0

add a note

User Contributed Notes 4 notes

Chad Lavoie
12 years ago
If using Unix Sockets, and you want to use SO_PEERCRED, you can use the number 17 for the optname (and SOL_SOCKET for the level).  The PID of the connecting process will be returned.
recycling dot sp dot am at gmail dot com
12 years ago
Just 2 notes here:
- On UNIX, If SO_DEBUG is set, the php program needs an effective user id of 0.
-  activating SO_OOBINLINE on a socket is equivalent to passing MSG_OOB flag to each recieving functions used with that socket (eg: socket_recv, socket_recvfrom).
prennings at gmail dot com
8 years ago
I was playing around with this option to use multiply socket connections with same hostname and same port (IRC). However the socket function needed for this is SO_REUSEPORT.

Though the majority of linux distro's does not have that yet officially implented in there distro's.

However for debian there is an patch that can be installed to get it working:

it has some work but I got it working after a while (Noobie in debian) maybe some other people are facing the same problem as I was.
skydiablo at gmx dot net
10 months ago
to receive UDP DHCP packets on a dedicated interface, you have to use the undocumented option SO_BINDTODEVICE:

= socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);

socket_set_option($socket, SOL_SOCKET, SO_BINDTODEVICE, 'eth1');
socket_set_option($socket, SOL_SOCKET, SO_BROADCAST, 1);
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
socket_set_option($socket, SOL_SOCKET, SO_REUSEPORT, 1);

socket_bind($socket, '', 67);
while (
1) {
    if (
$src = @socket_recv($socket, $data, 9999, 0)) {
$data . PHP_EOL;
To Top