You are calling
socket_bind
twice:
socket_bind($sock, $address, $port);
if (socket_bind($sock, $address, $port) === false) {
echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
}
The first call succeeds and the second fails because you can't bind to an IP address and port that is already in use. Remove the first call. Same for
socket_listen
below.