Configuration
PHPStreamServer allows you to define settings at different levels of the application.
Configurations can be applied in the Server constructor, Plugin constructor, and Worker constructor.
It is recommended to use named parameters when defining configuration options.
use PHPStreamServer\Core\Server;
use PHPStreamServer\Core\Worker\WorkerProcess;
use PHPStreamServer\Plugin\HttpServer\HttpServerPlugin;
$server = new Server(
// Server configuration
);
$server->addPlugin(
new HttpServerPlugin(
// Plugin configuration
),
);
$server->addWorker(
new WorkerProcess(
// Worker configuration
),
);
Server configuration
Server-level configuration defines global settings that apply to the entire application and affect all workers.
Option | Type | Default | Description |
---|---|---|---|
pidFile | string | not set | Optional. Path to the pid file. |
socketFile | string | not set | Optional. Path to the Unix socket file used for inter-process communication. |
stopTimeout | int | 10 | Optional. Maximum time to wait before forcefully terminating workers during shutdown. |
restartDelay | float | 0.25 | Optional. Delay between worker restarts. |
Plugin configuration
🔌 HttpServerPlugin
This is the part of Http Server Plugin
Option | Type | Default | Description |
---|---|---|---|
http2Enable | bool | true | Optional. Enables support for HTTP/2 protocol. |
httpConnectionTimeout | int | 60 | Optional. Timeout duration for idle HTTP connections. |
httpHeaderSizeLimit | int | 32768 | Optional. Maximum allowed size for HTTP headers. |
httpBodySizeLimit | int | 131072 | Optional. Maximum allowed size for the HTTP request body. |
gzipMinLength | int | 860 | Optional. Minimum response size required to enable gzip compression. |
gzipTypesRegex | string | * | Optional. Regular expression to match content types eligible for gzip compression. |
* #^(?:text/.*+|[^/]*+/xml|[^+]*\+xml|application/(?:json|(?:x-)?javascript))$#i
🔌 SchedulerPlugin
This is the part of Scheduler Plugin
This plugin does not have any specific configurable options.
🔌 LoggerPlugin
This is the part of Logger Plugin
Option | Type | Default | Description |
---|---|---|---|
handlers | ...Handler | not set | A list of logger handlers that define the destinations for the logs. |
🔌 FileMonitorPlugin
This is the part of File Monitor Plugin
Option | Type | Default | Description |
---|---|---|---|
watch | ...WatchDir | not set | List of WatchDir objects that define the files to monitor for changes. |
🔌 MetricsPlugin
This is the part of Metrics Plugin
Option | Type | Default | Description |
---|---|---|---|
listen | string|Listen | not set | The address at which the metrics server is listening. |
Worker configuration
Worker-level configuration applies to individual workers, allowing you to control their specific behavior.
PHPStreamServer provides several built-in worker types out of the box. Additionally, plugins can add new worker types, enhancing functionality.
Worker can be added to the server using the Server::addWorker()
method.
⚙️ WorkerProcess
This worker type is designed for running long-running PHP code.
Option | Type | Default | Description |
---|---|---|---|
name | string | not set | Optional. The name associated with the worker process. |
count | int | 1 | Optional. The number of processes to start. |
reloadable | bool | true | Optional. Whether the worker can be reloaded with the reload command. |
user | string | not set | Optional. Unix user of process. Current user by default. |
group | string | not set | Optional. Unix group of process. Current group by default. |
onStart | Closure | not set | Optional. A callback function executed when the worker starts. |
onStop | Closure | not set | Optional. A callback function executed when the worker stops. |
onReload | Closure | not set | Optional. A callback function executed when the worker reloads. |
reloadStrategies | ReloadStrategy[] | not set | Optional. The strategies used to reload the worker. |
⚙️ ExternalProcess
This worker type is designed for running external programs or scripts, enabling PHPStreamServer to manage external processes outside of PHP.
Option | Type | Default | Description |
---|---|---|---|
name | string | not set | Optional. The name associated with the worker process. |
count | int | 1 | Optional. The number of processes to start. |
reloadable | bool | true | Optional. Whether the worker can be reloaded with the reload command. |
user | string | not set | Optional. Unix user of process. Current user by default. |
group | string | not set | Optional. Unix group of process. Current group by default. |
command | string | not set | The external command or script to execute. |
⚙️🔌 HttpServerProcess
This is the part of Http Server Plugin
This worker type is designed to handle incoming HTTP requests asynchronously.
Option | Type | Default | Description |
---|---|---|---|
listen | string|Listen|Listen[] | not set | The address at which the server is listening. |
name | string | "HTTP Server" | Optional. The name associated with the worker process. |
count | int | 1 | Optional. The number of processes to start. |
reloadable | bool | true | Optional. Whether the worker can be reloaded with the reload command. |
user | string | not set | Optional. Unix user of process. Current user by default. |
group | string | not set | Optional. Unix group of process. Current group by default. |
onStart | Closure | not set | Optional. A callback function executed when the worker starts. |
onRequest | Closure | not set | Optional. A callback function executed when an HTTP request is received. |
onStop | Closure | not set | Optional. A callback function executed when the worker stops. |
onReload | Closure | not set | Optional. A callback function executed when the worker reloads. |
middleware | Middleware[] | not set | Optional. A list of middlewares for processing HTTP requests. |
reloadStrategies | ReloadStrategy[] | not set | Optional. The strategies used to reload the worker. |
serverDir | string | not set | Optional. The directory to serve static files from. |
accessLog | bool | true | Optional. Whether to log incoming HTTP requests. |
gzip | bool | false | Optional. Enables gzip compression. |
connectionLimit | int | not set | Optional. The maximum number of connections per worker. |
connectionLimitPerIp | int | not set | Optional. The maximum number of connections allowed per IP. |
concurrencyLimit | int | not set | Optional. The maximum number of concurrent HTTP requests per worker. |