xref: /php-uv/examples/poll.php (revision 99312394)
1<?php
2
3$socket = stream_socket_server("tcp://0.0.0.0:9999", $errno, $errstr);
4stream_set_blocking($socket, 0);
5
6$poll = uv_poll_init(uv_default_loop(), $socket);
7
8uv_poll_start($poll, UV::READABLE, function($poll, $stat, $ev, $socket) {
9    echo "parent poll:\n";
10    var_dump($stat);
11    $conn = stream_socket_accept($socket);
12
13    $pp = uv_poll_init(uv_default_loop(), $conn);
14    uv_poll_start($pp, UV::WRITABLE, function($poll, $stat, $ev, $conn) {
15        echo "  cb";
16        var_dump($stat);
17        var_dump($conn);
18
19        uv_poll_stop($poll);
20        uv_fs_write(uv_default_loop(), $conn, "Hello World", -1, function($conn, $nwrite) {
21            var_dump($conn);
22            fclose($conn);
23        });
24    });
25});
26
27uv_run();
28