<?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;
}
?>