Coroutine\Socket->getOption

需要v4.3.2及以上版本

function Coroutine\Socket->getOption(int $level, int $optname) : mixed

此方法对应getsockopt系统调用, 详情可参见man getsockopt文档。

此方法和sockets扩展的socket_get_option功能等价, 可以参见PHP文档

参数

level

level参数指定选项所在的协议级别。 例如,要在套接字级别检索选项,将使用SOL_SOCKET 的“level”参数。

可以通过指定该级别的协议编号来使用其他级别,例如TCP。 可以使用getprotobyname函数找到协议号。

optname

Option Description Type
SO_DEBUG 报告是否正在记录调试信息。 int
SO_BROADCAST 报告是否支持广播消息的传输。 int
SO_REUSEADDR 报告是否可以重用本地地址。 int
SO_REUSEPORT 报告是否可以重用本地端口。 int
SO_KEEPALIVE 通过定期传输消息来报告连接是否保持活动状态。如果连接的套接字无法响应这些消息,则连接断开,并且使用SIGPIPE信号通知写入该套接字的进程。 int
SO_LINGER 如果数据存在,报告socket是否在socket_close()上徘徊。默认情况下,当套接字关闭时,它会尝试发送所有未发送的数据。在面向连接的套接字的情况下,socket_close()将等待其对等方确认数据。如果l_onoff为非-zero和l_lingeris为零,所有未发送的数据都将被丢弃,并且在面向连接的套接字的情况下,RST(重置)被发送给对等体。另一方面,如果l_onoff为非零且l_linger为非零,socket_close()将阻塞,直到所有数据都被发送或l_linger中指定的时间过去。如果套接字是非阻塞的,socket_close()将失败并返回错误 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 buffer. 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())
SO_TYPE Reports the socket type (e.g.SOCK_STREAM). int (cannot be set by socket_set_option())
SO_DONTROUTE Reports whether outgoing messages bypass the standard routing facilities. int
SO_RCVLOWAT Reports the minimum number of bytes to process for socket input operations. 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 timeout value.
SO_SNDTIMEO Reports the timeout value specifying the amount of time that an output 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 timeout value.
SO_SNDLOWAT Reports the minimum number of bytes to process for socket output operations. int
TCP_NODELAY Reports whether the Nagle TCP algorithm 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 multicast address and "interface", specifying either an interface number (type int) or a string with the interface name, like "eth0". 0 can be specified to indicate the interface should be selected using routing rules. (can only be used in socket_set_option())
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())
MCAST_BLOCK_SOURCE Blocks packets arriving from a specific source to a specific multicast group, which must have been previously 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())
MCAST_UNBLOCK_SOURCE Unblocks (start receiving again) packets arriving from a specific source address to a specific multicast 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())
MCAST_JOIN_SOURCE_GROUP Receive packets destined to a specific 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())
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())
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 selection. The function socket_get_option() 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_MULTICAST_IF andIPV6_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() 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.