diff --git a/docs/classic.md b/docs/classic.md index 5d89cfba..3b40bc63 100644 --- a/docs/classic.md +++ b/docs/classic.md @@ -2,8 +2,10 @@ Without any additional configuration, FrankenPHP operates in classic mode. In this mode, FrankenPHP functions like a traditional PHP server, directly serving PHP files. This makes it a seamless drop-in replacement for PHP-FPM or Apache with mod_php. -Similar to Caddy, FrankenPHP accepts an unlimited number of connections and uses a [fixed number of threads](config.md#caddyfile-config) to serve them. The number of accepted and queued connections is limited only by the available system resources. The PHP thread pool operates with a fixed number of threads initialized at startup, comparable to the static mode of PHP-FPM. +Similar to Caddy, FrankenPHP accepts an unlimited number of connections and uses a [fixed number of threads](config.md#caddyfile-config) to serve them. The number of accepted and queued connections is limited only by the available system resources. +The PHP thread pool operates with a fixed number of threads initialized at startup, comparable to the static mode of PHP-FPM. It's also possible to let threads [scale automatically at runtime](performance.md#max_threads), similar to the dynamic mode of PHP-FPM. -Queued connections will wait indefinitely until a PHP thread is available to serve them. To prevent that, set a reasonable [write timeout in Caddy](https://caddyserver.com/docs/caddyfile/options#timeouts). +Queued connections will wait indefinitely until a PHP thread is available to serve them. To prevent that, you can use the `max_wait_time` [configuration](config.md#caddyfile-config) to limit how long a request may wait for a free PHP thread before being rejected. +Additionally, you can set a reasonable [write timeout in Caddy](https://caddyserver.com/docs/caddyfile/options#timeouts). Each Caddy instance will only spin up one FrankenPHP thread pool, which will be shared across all `php_server` blocks. diff --git a/docs/config.md b/docs/config.md index 61fc6b5d..2d5cdbc6 100644 --- a/docs/config.md +++ b/docs/config.md @@ -52,6 +52,7 @@ Optionally, the number of threads to create and [worker scripts](worker.md) to s frankenphp { num_threads # Sets the number of PHP threads to start. Default: 2x the number of available CPUs. max_threads # Limits the number of additional PHP threads that can be started at runtime. Default: num_threads. Can be set to 'auto'. + max_wait_time # Sets the maximum time a request may wait for a free PHP thread before timing out. Default: disabled. php_ini # Set a php.ini directive. Can be used several times to set multiple directives. worker { file # Sets the path to the worker script. diff --git a/docs/performance.md b/docs/performance.md index 2f111522..19a29a96 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -19,12 +19,12 @@ To change the number of workers, use the `num` option of the `worker` section of ### `max_threads` While it's always better to know exactly what your traffic will look like, real-life applications tend to be more -unpredictable. The `max_threads` allows FrankenPHP to automatically spawn additional threads at runtime up to the specified limit. -`max_threads` can help you -figure out how many threads you need to handle your traffic and can make the server more resilient to latency spikes. +unpredictable. The `max_threads` [configuration](config.md#caddyfile-config) allows FrankenPHP to automatically spawn additional threads at runtime up to the specified limit. +`max_threads` can help you figure out how many threads you need to handle your traffic and can make the server more resilient to latency spikes. If set to `auto`, the limit will be estimated based on the `memory_limit` in your `php.ini`. If not able to do so, -`auto` will instead default to 2x `num_threads`. -`max_threads is similar to PHP FPM's [pm.max_children](https://www.php.net/manual/en/install.fpm.configuration.php#pm.max-children). +`auto` will instead default to 2x `num_threads`. Keep in mind that `auto` might strongly underestimate the number of threads needed. +`max_threads` is similar to PHP FPM's [pm.max_children](https://www.php.net/manual/en/install.fpm.configuration.php#pm.max-children). The main difference is that FrankenPHP uses threads instead of +processes and automatically delegates them across different worker scripts and 'classic mode' as needed. ## Worker Mode