array( 'local_cert' => isset($argv[2]) ? $argv[2] : (__DIR__ . '/localhost.pem') ) )); $server->on('connection', function (ConnectionInterface $conn) { $conn->once('data', function () use ($conn) { $body = "

Hello world!

\r\n"; $conn->end("HTTP/1.1 200 OK\r\nContent-Length: " . strlen($body) . "\r\nConnection: close\r\n\r\n" . $body); }); }); $server->on('error', 'printf'); echo 'Listening on ' . strtr($server->getAddress(), array('tcp:' => 'http:', 'tls:' => 'https:')) . PHP_EOL; $loop->run();