This read-only repository mirrors
packages/demo. Open issues and pull requests in the thesis-php/thesis monorepo.
This small HTTP server shows how requests overlap while a handler waits. Open the
home page for links to the demo routes.
GET /wait/250ms waits for the requested duration and returns Waited for 250ms. With no duration, GET /wait returns Waited for 0s.
GET /error throws an exception so you can see how the server handles a failed request.
Use 64-bit PHP 8.6 with Io\Poll\Context and ext-pcntl on Unix. Once the split is on Packagist, install
the development version with Composer.
composer create-project thesis/demo demo dev-main
cd demo
php app.phpTo restart the installed server automatically whenever you save app.php or index.html, start it with
thesis/hot-reload.
vendor/bin/hot-reload --watch app.php --watch index.html -- php app.phpThe server listens on all IPv4 interfaces on ports 18080 (HTTP) and 18443 (HTTPS). The demo ships a self-signed localhost certificate and its private key for local development. From the installed project, verify HTTPS on port 18443 with:
curl --cacert tls/localhost.crt https://localhost:18443/waitFrom the monorepo root, run make install, then publish both ports on loopback:
docker compose run --rm -p 127.0.0.1:18080:18080 -p 127.0.0.1:18443:18443 php php packages/demo/app.phpTo watch the demo in Docker, run this from the same directory:
docker compose run --rm -p 127.0.0.1:18080:18080 -p 127.0.0.1:18443:18443 php \
packages/hot-reload/bin/hot-reload --watch packages/demo/app.php --watch packages/demo/index.html \
-- php packages/demo/app.phpIn another terminal, send the same eight requests sequentially and then concurrently.
time curl -fsS 'http://127.0.0.1:18080/wait/25[0-7]ms'
time curl -fsS --parallel --parallel-immediate 'http://127.0.0.1:18080/wait/25[0-7]ms'On an idle machine, expect about two seconds for the first command and about 250 ms for the second. The console shows the path and duration of each finished request. Press Ctrl+C to stop the server and drain its logs.
The server and logger are wired in app.php.