Manage a worker pool

← All configuration scenarios

You want two application processes and a way to replace workers while the service is running. Enable a private management socket alongside a fixed worker count.

Start two workers

Save this as pool.json in the application root. Use a distinct socket name if you run multiple servers under the same account.

JSON
{
  "listen": { "port": 9000 },
  "workers": {
    "count": 2,
    "rotation": { "max_concurrent": 1, "drain_timeout_seconds": 30 }
  },
  "control": { "socket": "@runtime/example-pool.sock" }
}
Shell
php vendor/mini4work/webserver/examples/server.php pool.json

Inspect and replace workers

In a second terminal under the same account, query the supervisor. Status returns JSON including its state and uptime.

Shell
client=vendor/mini4work/webserver/examples/control.php
socket=@runtime/example-pool.sock
php "$client" "$socket" status

On this example instance, request replacement. The control client prints Accepted when the supervisor accepts the command. Check the server log for worker turnover and send another request after replacement.

Shell
php "$client" "$socket" restart-workers
curl -i http://127.0.0.1:9000/hello

Expect HTTP 200 and a worker_pid from the serving pool. The rotation limit permits one replacement at a time. Draining gives admitted work up to 30 seconds to finish. See worker lifecycle settings for automatic request, age and memory triggers.