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, true); fclose($csock); } else { fclose($csock); } } function create_certificate($pemfile) { global $CONFIG; $certificateData = array( "countryName" => "US", "stateOrProvinceName" => "New York", "localityName" => "New York City", "organizationName" => "Rocksolid", "organizationalUnitName" => "Rocksolid Light", "commonName" => $CONFIG['organization'], "emailAddress" => "rocksolid@example.com" ); // Generate certificate $privateKey = openssl_pkey_new(); $certificate = openssl_csr_new($certificateData, $privateKey); $certificate = openssl_csr_sign($certificate, null, $privateKey, 365); // Generate PEM file $pem_passphrase = null; // empty for no passphrase $pem = array(); openssl_x509_export($certificate, $pem[0]); openssl_pkey_export($privateKey, $pem[1], $pem_passphrase); $pem = implode($pem); // Save PEM file file_put_contents($pemfile, $pem); } ?>