Example #1
0
function server($port)
{
    echo "Starting server at port {$port}...\n";
    $socket = @stream_socket_server("tcp://localhost:{$port}", $errNo, $errStr);
    if (!$socket) {
        throw new Exception($errStr, $errNo);
    }
    stream_set_blocking($socket, 0);
    $socket = new CoSocket($socket);
    while (true) {
        (yield SystemCall::newTask(handleClient((yield $socket->accept()))));
    }
}