Skip to content
thesis-phpPublic

About

A small HTTP server with console logging that shows how concurrent requests overlap.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

Thesis Demo

PHP Release License PHPStan

This read-only repository mirrors packages/demo. Open issues and pull requests in the thesis-php/thesis monorepo.

Report a bug · Request a feature · Changelog · Contributing

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.

Run

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.php

To 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.php

The 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/wait

From 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.php

To 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.php

Compare requests

In 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.

About

A small HTTP server with console logging that shows how concurrent requests overlap.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages