0) { handle_client($sock, $connection); } else { echo "error: " . socket_strerror($connection); file_put_contents($logfile, "\n" . format_log_date() . " error: " . socket_strerror($connection), FILE_APPEND); die(); } } } /** * Signal handler */ function sig_handler($sig) { switch ($sig) { case SIGTERM: case SIGINT: exit(); break; case SIGCHLD: pcntl_waitpid(- 1, $status); break; } } /** * Handle a new client connection */ function handle_client($ssock, $csock) { GLOBAL $__server_listening; $pid = pcntl_fork(); if ($pid == - 1) { /* fork failed */ echo "fork failure!\n"; die(); } elseif ($pid == 0) { /* child process */ $__server_listening = false; fclose($ssock); interact($csock, false); fclose($csock); } else { fclose($csock); } } ?>