SOCKET_GET_OPTION(3) 1 SOCKET_GET_OPTION(3)
socket_get_option - Gets socket options for the socket
SYNOPSIS
mixed socket_get_option (resource $socket, int $level, int $optname)
DESCRIPTION
The socket_get_option(3) function retrieves the value for the option specified by the $optname parameter for the specified $socket.
PARAMETERS
o $socket
- A valid socket resource created with socket_create(3) or socket_accept(3).
o $level
- The $level parameter specifies the protocol level at which the option resides. For example, to retrieve options at the socket
level, a $level parameter of SOL_SOCKET would be used. Other levels, such as TCP, can be used by specifying the protocol number of
that level. Protocol numbers can be found by using the getprotobyname(3) function.
o $optname
-
Available Socket Options
+-------------------------+--------------------------------------+---+
| Option | | |
| | | |
| | Description | |
| | | |
| | Type | |
| | | |
+-------------------------+--------------------------------------+---+
| | | |
| SO_DEBUG | | |
| | | |
| | Reports whether debugging informa- | |
| | tion is being recorded. | |
| | | |
| | | |
| | int | |
| | | |
| | | |
| SO_BROADCAST | | |
| | | |
| | Reports whether transmission of | |
| | broadcast messages is supported. | |
| | | |
| | | |
| | int | |
| | | |
| | | |
| SO_REUSEADDR | | |
| | | |
| | Reports whether local addresses can | |
| | be reused. | |
| | | |
| | | |
| | int | |
| | | |
| | | |
| SO_KEEPALIVE | | |
| | | |
| | Reports whether connections are | |
| | kept active with periodic transmis- | |
| | sion of messages. If the connected | |
| | socket fails to respond to these | |
| | messages, the connection is broken | |
| | and processes writing to that socket | |
| | are notified with a SIGPIPE signal. | |
| | | |
| | | |
| | int | |
| | | |
| | | |
| SO_LINGER | | |
| | | |
| | Reports whether the $socket lingers | |
| | on socket_close(3) if data is | |
| | present. By default, when the socket | |
| | is closed, it attempts to send all | |
| | unsent data. In the case of a con- | |
| | nection-oriented socket, | |
| | socket_close(3) will wait for its | |
| | peer to acknowledge the data. If | |
| | $l_onoff is non-zero and $l_linger | |
| | is zero, all the unsent data will be | |
| | discarded and RST (reset) is sent to | |
| | the peer in the case of a connec- | |
| | tion-oriented socket. On the other | |
| | hand, if $l_onoff is non-zero and | |
| | $l_linger is non-zero, | |
| | socket_close(3) will block until all | |
| | the data is sent or the time speci- | |
| | fied in $l_linger elapses. If the | |
| | socket is non-blocking, | |
| | socket_close(3) will fail and return | |
| | an error. | |
| | | |
| | | |
| | array. The array will contain two | |
| | keys: $l_onoff and $l_linger. | |
| | | |
| | | |
| SO_OOBINLINE | | |
| | | |
| | Reports whether the $socket leaves | |
| | out-of-band data inline. | |
| | | |
| | | |
| | int | |
| | | |
| | | |
| SO_SNDBUF | | |
| | | |
| | Reports the size of the send buf- | |
| | fer. | |
| | | |
| | | |
| | int | |
| | | |
| | | |
| SO_RCVBUF | | |
| | | |
| | Reports the size of the receive | |
| | buffer. | |
| | | |
| | | |
| | int | |
| | | |
| | | |
| SO_ERROR | | |
| | | |
| | Reports information about error | |
| | status and clears it. | |
| | | |
| | | |
| | int (cannot be set by | |
| | socket_set_option(3)) | |
| | | |
| | | |
| SO_TYPE | | |
| | | |
| | Reports the $socket type (e.g. | |
| | SOCK_STREAM). | |
| | | |
| | | |
| | int (cannot be set by | |
| | socket_set_option(3)) | |
| | | |
| | | |
| SO_DONTROUTE | | |
| | | |
| | Reports whether outgoing messages | |
| | bypass the standard routing facili- | |
| | ties. | |
| | | |
| | | |
| | int | |
| | | |
| | | |
| SO_RCVLOWAT | | |
| | | |
| | Reports the minimum number of bytes | |
| | to process for $socket input opera- | |
| | tions. | |
| | | |
| | | |
| | int | |
| | | |
| | | |
| SO_RCVTIMEO | | |
| | | |
| | Reports the timeout value for input | |
| | operations. | |
| | | |
| | | |
| | array. The array will contain two | |
| | keys: $sec which is the seconds part | |
| | on the timeout value and $usec which | |
| | is the microsecond part of the time- | |
| | out value. | |
| | | |
| | | |
| SO_SNDTIMEO | | |
| | | |
| | Reports the timeout value specify- | |
| | ing the amount of time that an out- | |
| | put function blocks because flow | |
| | control prevents data from being | |
| | sent. | |
| | | |
| | | |
| | array. The array will contain two | |
| | keys: $sec which is the seconds part | |
| | on the timeout value and $usec which | |
| | is the microsecond part of the time- | |
| | out value. | |
| | | |
| | | |
| SO_SNDLOWAT | | |
| | | |
| | Reports the minimum number of bytes | |
| | to process for $socket output opera- | |
| | tions. | |
| | | |
| | | |
| | int | |
| | | |
| | | |
| TCP_NODELAY | | |
| | | |
| | Reports whether the Nagle TCP algo- | |
| | rithm is disabled. | |
| | | |
| | | |
| | int | |
| | | |
| | | |
| MCAST_JOIN_GROUP | | |
| | | |
| | Joins a multicast group. (added in | |
| | PHP 5.4) | |
| | | |
| | | |
| | array with keys "group", specifying | |
| | a string with an IPv4 or IPv6 multi- | |
| | cast address and "interface", speci- | |
| | fying either an interface number | |
| | (type int) or a string with the | |
| | interface name, like "eth0". 0 can | |
| | be specified to indicate the inter- | |
| | face should be selected using rout- | |
| | ing rules. (can only be used in | |
| | socket_set_option(3)) | |
| | | |
| | | |
| MCAST_LEAVE_GROUP | | |
| | | |
| | Leaves a multicast group. (added in | |
| | PHP 5.4) | |
| | | |
| | | |
| | array. See MCAST_JOIN_GROUP for more | |
| | information. (can only be used in | |
| | socket_set_option(3)) | |
| | | |
| | | |
| MCAST_BLOCK_SOURCE | | |
| | | |
| | Blocks packets arriving from a spe- | |
| | cific source to a specific multicast | |
| | group, which must have been previ- | |
| | ously joined. (added in PHP 5.4) | |
| | | |
| | | |
| | array with the same keys as | |
| | MCAST_JOIN_GROUP, plus one extra | |
| | key, source, which maps to a string | |
| | specifying an IPv4 or IPv6 address | |
| | of the source to be blocked. (can | |
| | only be used in | |
| | socket_set_option(3)) | |
| | | |
| | | |
| MCAST_UNBLOCK_SOURCE | | |
| | | |
| | Unblocks (start receiving again) | |
| | packets arriving from a specific | |
| | source address to a specific multi- | |
| | cast group, which must have been | |
| | previously joined. (added in PHP | |
| | 5.4) | |
| | | |
| | | |
| | array with the same format as | |
| | MCAST_BLOCK_SOURCE. (can only be | |
| | used in socket_set_option(3)) | |
| | | |
| | | |
|MCAST_JOIN_SOURCE_GROUP | | |
| | | |
| | Receive packets destined to a spe- | |
| | cific multicast group whose source | |
| | address matches a specific value. | |
| | (added in PHP 5.4) | |
| | | |
| | | |
| | array with the same format as | |
| | MCAST_BLOCK_SOURCE. (can only be | |
| | used in socket_set_option(3)) | |
| | | |
| | | |
|MCAST_LEAVE_SOURCE_GROUP | | |
| | | |
| | Stop receiving packets destined to | |
| | a specific multicast group whose | |
| | soure address matches a specific | |
| | value. (added in PHP 5.4) | |
| | | |
| | | |
| | array with the same format as | |
| | MCAST_BLOCK_SOURCE. (can only be | |
| | used in socket_set_option(3)) | |
| | | |
| | | |
| IP_MULTICAST_IF | | |
| | | |
| | The outgoing interface for IPv4 | |
| | multicast packets. (added in PHP | |
| | 5.4) | |
| | | |
| | Either int specifying the interface | |
| | number or a string with an interface | |
| | name, like eth0. The value 0 can be | |
| | used to indicate the routing table | |
| | is to used in the interface selec- | |
| | tion. The function | |
| | socket_get_option(3) returns an | |
| | interface index. Note that, unlike | |
| | the C API, this option does NOT take | |
| | an IP address. This eliminates the | |
| | interface difference between IP_MUL- | |
| | TICAST_IF and IPV6_MULTICAST_IF. | |
| | | |
| | | |
| IPV6_MULTICAST_IF | | |
| | | |
| | The outgoing interface for IPv6 | |
| | multicast packets. (added in PHP | |
| | 5.4) | |
| | | |
| | The same as IP_MULTICAST_IF. | |
| | | |
| | | |
| IP_MULTICAST_LOOP | | |
| | | |
| | The multicast loopback policy for | |
| | IPv4 packets, which determines | |
| | whether multicast packets sent by | |
| | this socket also reach receivers in | |
| | the same host that have joined the | |
| | same multicast group on the outgoing | |
| | interface used by this socket. This | |
| | is the case by default. (added in | |
| | PHP 5.4) | |
| | | |
| | | |
| | int (either 0 or 1). For | |
| | socket_set_option(3) any value will | |
| | be accepted and will be converted to | |
| | a boolean following the usual PHP | |
| | rules. | |
| | | |
| | | |
| IPV6_MULTICAST_LOOP | | |
| | | |
| | Analogous to IP_MULTICAST_LOOP, but | |
| | for IPv6. (added in PHP 5.4) | |
| | | |
| | | |
| | int. See IP_MULTICAST_LOOP. | |
| | | |
| | | |
| IP_MULTICAST_TTL | | |
| | | |
| | The time-to-live of outgoing IPv4 | |
| | multicast packets. This should be a | |
| | value between 0 (don't leave the | |
| | interface) and 255. The default | |
| | value is 1 (only the local network | |
| | is reached). (added in PHP 5.4) | |
| | | |
| | | |
| | int between 0 and 255. | |
| | | |
| | | |
| IPV6_MULTICAST_HOPS | | |
| | | |
| | Analogous to IP_MULTICAST_TTL, but | |
| | for IPv6 packets. The value -1 is | |
| | also accepted, meaning the route | |
| | default should be used. (added in | |
| | PHP 5.4) | |
| | | |
| | | |
| | int between -1 and 255. | |
| | | |
+-------------------------+--------------------------------------+---+
RETURN VALUES
Returns the value of the given option, or FALSE on errors.
EXAMPLES
Example #1
socket_set_option(3) example
<?php
$socket = socket_create_listen(1223);
$linger = array('l_linger' => 1, 'l_onoff' => 1);
socket_set_option($socket, SOL_SOCKET, SO_LINGER, $linger);
var_dump(socket_get_option($socket, SOL_SOCKET, SO_REUSEADDR));
?>
PHP Documentation Group SOCKET_GET_OPTION(3)