socket_set_option
socket_set_option
Sets socket options for the socket
bool **socket_set_option** Socket $socket int $level int $option $value
The function sets the option
specified by the parameter, at the
specified protocol , to the value pointed to
by the parameter for the
.
socket_set_option``option``level``value``socket
socket
A instance created with
or .
Socket``socket_create``socket_accept
level
The parameter specifies the protocol
level at which the option resides. For example, to set options at
the socket level, a parameter of
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
function.
level``level``SOL_SOCKET``getprotobyname
option
The available socket options are the same as those for the
function.
socket_get_option
valueThe option value.
return.success
Voorbeeld: 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;
}
?>
socket_create``socket_bind``socket_strerror``socket_last_error``socket_get_option