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)); } } }
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)); } } }
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())))); } }
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())))); } }
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))); } }
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())))); } }