Esempio n. 1
0
function task()
{
    $tid = (yield getTaskId());
    $childTid = (yield newTask(childTask()));
    for ($i = 1; $i <= 6; ++$i) {
        echo "Parent task {$tid} iteration {$i}.\n";
        yield;
        if ($i == 3) {
            (yield killTask($childTid));
        }
    }
}
Esempio n. 2
0
function parentTask()
{
    $tid = (yield getTaskId());
    $childTid = (yield newTask(childTask()));
    for ($i = 1; $i <= 6; $i++) {
        echo "Parent task {$tid} iteration {$i}.<br>";
        yield;
        if ($i == 3) {
            echo "Parent sending message to kill child task.<br>";
            (yield killTask($childTid));
        }
    }
}
Esempio n. 3
0
function server($port)
{
    echo "SERVER LISTENING ON: {$port}" . PHP_EOL . PHP_EOL;
    $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 newTask(handleClient((yield $socket->accept()))));
    }
}
Esempio n. 4
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);
    /*     while (true) {
            echo "server wait for read\n";
            var_dump($socket);
            yield waitForRead($socket);
            $clientSocket = stream_socket_accept($socket, 0);
            yield newTask(handleClient($clientSocket));
        } */
    $socket = new CoSocket($socket);
    while (true) {
        echo "server before newTask\n";
        (yield newTask(handleClient((yield $socket->accept()))));
    }
}
Esempio n. 5
0
function server($port)
{
    echo "Starting server at port {$port}...\n";
    //$socket = @stream_socket_server("tcp://*****:*****@stream_socket_server("tcp://0:{$port}", $errNo, $errStr);
    if (!$socket) {
        throw new Exception($errStr, $errNo);
    }
    stream_set_blocking($socket, 0);
    while (true) {
        echo "server:waitForRead\n";
        (yield waitForRead($socket));
        $clientSocket = stream_socket_accept($socket, 0);
        echo "server:handleClient\n";
        (yield newTask(handleClient($clientSocket)));
    }
}
Esempio n. 6
0
function server($port)
{
    echo "Starting server at port {$port}...\n";
    $socket = @stream_socket_server("tcp://0:{$port}", $errNo, $errStr);
    if (!$socket) {
        throw new Exception($errStr, $errNo);
    }
    stream_set_blocking($socket, 0);
    $socket = new CoSocket($socket);
    while (true) {
        (yield newTask(handleClient((yield $socket->accept()))));
    }
}