array( 'local_cert' => isset($argv[2]) ? $argv[2] : (__DIR__ . '/localhost.pem') ) )); $server->on('connection', function (ConnectionInterface $conn) use ($loop) { echo '[connected]' . PHP_EOL; // count the number of bytes received from this connection $bytes = 0; $conn->on('data', function ($chunk) use (&$bytes) { $bytes += strlen($chunk); }); // report average throughput once client disconnects $t = microtime(true); $conn->on('close', function () use ($conn, $t, &$bytes) { $t = microtime(true) - $t; echo '[disconnected after receiving ' . $bytes . ' bytes in ' . round($t, 3) . 's => ' . round($bytes / $t / 1024 / 1024, 1) . ' MiB/s]' . PHP_EOL; }); }); $server->on('error', 'printf'); echo 'Listening on ' . $server->getAddress() . PHP_EOL; $loop->run();