Query: socket_set_option
OS: php
Section: 3
Format: Original Unix Latex Style Formatted with HTML and a Horizontal Scroll Bar
SOCKET_SET_OPTION(3) 1 SOCKET_SET_OPTION(3) socket_set_option - Sets socket options for the socketSYNOPSISbool socket_set_option (resource $socket, int $level, int $optname, mixed $optval)DESCRIPTIONThe socket_set_option(3) function sets the option specified by the $optname parameter, at the specified protocol $level, to the value pointed to by the $optval parameter for the $socket.PARAMETERSo $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 - The available socket options are the same as those for the socket_get_option(3) function. o $optval - The option value.RETURN VALUESReturns TRUE on success or FALSE on failure.EXAMPLESExample #1 socket_set_option(3) example <?php $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if (!is_resource($socket)) { echo 'Unable to create socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) { echo 'Unable to set option on socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } if (!socket_bind($socket, '127.0.0.1', 1223)) { echo 'Unable to bind socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } $rval = socket_get_option($socket, SOL_SOCKET, SO_REUSEADDR); if ($rval === false) { echo 'Unable to get socket option: '. socket_strerror(socket_last_error()) . PHP_EOL; } else if ($rval !== 0) { echo 'SO_REUSEADDR is set on socket !' . PHP_EOL; } ?> PHP Documentation Group SOCKET_SET_OPTION(3)
Related Man Pages |
---|
getsockopt(2) - redhat |
getsockopt(2) - linux |
getsockopt(2) - centos |
setsockopt(2) - centos |
socket_create_pair(3) - php |
Similar Topics in the Unix Linux Community |
---|
socket options |
Socket programming in C |
TCP trashing data on application close |
Unable to pass a space inside a variable shell scripting |
Assigning value to a variable |