|
15 | 15 | // $ php examples/03-http-server.php 127.0.0.1:8000 |
16 | 16 | // $ curl -v http://localhost:8000/ |
17 | 17 | // $ ab -n1000 -c10 http://localhost:8000/ |
18 | | -// $ docker run -it --rm --net=host jordi/ab ab -n1000 -c10 http://localhost:8000/ |
| 18 | +// $ docker run -it --rm --net=host jordi/ab -n1000 -c10 http://localhost:8000/ |
19 | 19 | // |
20 | 20 | // You can also run a secure HTTPS echo server like this: |
21 | 21 | // |
22 | 22 | // $ php examples/03-http-server.php tls://127.0.0.1:8000 examples/localhost.pem |
23 | 23 | // $ curl -v --insecure https://localhost:8000/ |
24 | 24 | // $ ab -n1000 -c10 https://localhost:8000/ |
25 | | -// $ docker run -it --rm --net=host jordi/ab ab -n1000 -c10 https://localhost:8000/ |
| 25 | +// $ docker run -it --rm --net=host jordi/ab -n1000 -c10 https://localhost:8000/ |
26 | 26 | // |
27 | 27 | // You can also run a Unix domain socket (UDS) server like this: |
28 | 28 | // |
|
32 | 32 | // You can also use systemd socket activation and listen on an inherited file descriptor: |
33 | 33 | // |
34 | 34 | // $ systemd-socket-activate -l 8000 php examples/03-http-server.php php://fd/3 |
| 35 | +// $ curl -v --insecure https://localhost:8000/ |
| 36 | +// $ ab -n1000 -c10 https://localhost:8000/ |
| 37 | +// $ docker run -it --rm --net=host jordi/ab -n1000 -c10 https://localhost:8000/ |
35 | 38 |
|
36 | 39 | require __DIR__ . '/../vendor/autoload.php'; |
37 | 40 |
|
|
42 | 45 | )); |
43 | 46 |
|
44 | 47 | $socket->on('connection', function (React\Socket\ConnectionInterface $connection) { |
| 48 | + echo '[' . $connection->getRemoteAddress() . ' connected]' . PHP_EOL; |
| 49 | + |
45 | 50 | $connection->once('data', function () use ($connection) { |
46 | 51 | $body = "<html><h1>Hello world!</h1></html>\r\n"; |
47 | 52 | $connection->end("HTTP/1.1 200 OK\r\nContent-Length: " . strlen($body) . "\r\nConnection: close\r\n\r\n" . $body); |
48 | 53 | }); |
| 54 | + |
| 55 | + $connection->on('close', function () use ($connection) { |
| 56 | + echo '[' . $connection->getRemoteAddress() . ' disconnected]' . PHP_EOL; |
| 57 | + }); |
49 | 58 | }); |
50 | 59 |
|
51 | | -$socket->on('error', 'printf'); |
| 60 | +$socket->on('error', function (Exception $e) { |
| 61 | + echo 'Error: ' . $e->getMessage() . PHP_EOL; |
| 62 | +}); |
52 | 63 |
|
53 | 64 | echo 'Listening on ' . strtr($socket->getAddress(), array('tcp:' => 'http:', 'tls:' => 'https:')) . PHP_EOL; |
0 commit comments