Skip to main content

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.

OptionTypeDefaultDescription
pidFilestringnot setOptional. Path to the pid file.
socketFilestringnot setOptional. Path to the Unix socket file used for inter-process communication.
stopTimeoutint10Optional. Maximum time to wait before forcefully terminating workers during shutdown.
restartDelayfloat0.25Optional. Delay between worker restarts.

Plugin configuration

🔌 HttpServerPlugin

This is the part of Http Server Plugin

OptionTypeDefaultDescription
http2EnablebooltrueOptional. Enables support for HTTP/2 protocol.
httpConnectionTimeoutint60Optional. Timeout duration for idle HTTP connections.
httpHeaderSizeLimitint32768Optional. Maximum allowed size for HTTP headers.
httpBodySizeLimitint131072Optional. Maximum allowed size for the HTTP request body.
gzipMinLengthint860Optional. Minimum response size required to enable gzip compression.
gzipTypesRegexstring*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

OptionTypeDefaultDescription
handlers...Handlernot setA list of logger handlers that define the destinations for the logs.

🔌 FileMonitorPlugin

This is the part of File Monitor Plugin

OptionTypeDefaultDescription
watch...WatchDirnot setList of WatchDir objects that define the files to monitor for changes.

🔌 MetricsPlugin

This is the part of Metrics Plugin

OptionTypeDefaultDescription
listenstring|Listennot setThe 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.

OptionTypeDefaultDescription
namestringnot setOptional. The name associated with the worker process.
countint1Optional. The number of processes to start.
reloadablebooltrueOptional. Whether the worker can be reloaded with the reload command.
userstringnot setOptional. Unix user of process. Current user by default.
groupstringnot setOptional. Unix group of process. Current group by default.
onStartClosurenot setOptional. A callback function executed when the worker starts.
onStopClosurenot setOptional. A callback function executed when the worker stops.
onReloadClosurenot setOptional. A callback function executed when the worker reloads.
reloadStrategiesReloadStrategy[]not setOptional. 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.

OptionTypeDefaultDescription
namestringnot setOptional. The name associated with the worker process.
countint1Optional. The number of processes to start.
reloadablebooltrueOptional. Whether the worker can be reloaded with the reload command.
userstringnot setOptional. Unix user of process. Current user by default.
groupstringnot setOptional. Unix group of process. Current group by default.
commandstringnot setThe 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.

OptionTypeDefaultDescription
listenstring|Listen|Listen[]not setThe address at which the server is listening.
namestring"HTTP Server"Optional. The name associated with the worker process.
countint1Optional. The number of processes to start.
reloadablebooltrueOptional. Whether the worker can be reloaded with the reload command.
userstringnot setOptional. Unix user of process. Current user by default.
groupstringnot setOptional. Unix group of process. Current group by default.
onStartClosurenot setOptional. A callback function executed when the worker starts.
onRequestClosurenot setOptional. A callback function executed when an HTTP request is received.
onStopClosurenot setOptional. A callback function executed when the worker stops.
onReloadClosurenot setOptional. A callback function executed when the worker reloads.
middlewareMiddleware[]not setOptional. A list of middlewares for processing HTTP requests.
reloadStrategiesReloadStrategy[]not setOptional. The strategies used to reload the worker.
serverDirstringnot setOptional. The directory to serve static files from.
accessLogbooltrueOptional. Whether to log incoming HTTP requests.
gzipboolfalseOptional. Enables gzip compression.
connectionLimitintnot setOptional. The maximum number of connections per worker.
connectionLimitPerIpintnot setOptional. The maximum number of connections allowed per IP.
concurrencyLimitintnot setOptional. The maximum number of concurrent HTTP requests per worker.

⚙️🔌 PeriodicProcess

This is the part of Scheduler Plugin

This worker type is designed to execute tasks periodically.
The schedule option can be specified in one of the following formats:

  • Number of seconds (e.g. 60)
  • An ISO8601 datetime format (e.g. 2025-01-01 00:00:00)
  • An ISO8601 duration format (e.g. PT1M)
  • A relative date format (e.g. 1 minute)
  • A cron expression (e.g. */1 * * * *)
OptionTypeDefaultDescription
namestringnot setOptional. The name associated with the worker process.
scheduleint"1 minute"Optional. Schedule in one of the formats described above.
jitterint0Optional. Jitter in seconds that adds a random time offset to the schedule.
userintnot setOptional. Unix user of process. Current user by default.
groupintnot setOptional. Unix group of process. Current group by default.
onStartClosurenot setOptional. A callback function executed when the worker stops.

⚙️🔌 SymfonyHttpServerProcess

This is the part of Symfony bundle

This worker type is designed to run symfony application webserver.

OptionTypeDefaultDescription
listenstring|Listen|Listen[]not setThe address at which the server is listening.
countint1Optional. The number of processes to start.
reloadablebooltrueOptional. Whether the worker can be reloaded with the reload command.
userstringnot setOptional. Unix user of process. Current user by default.
groupstringnot setOptional. Unix group of process. Current group by default.
middlewareMiddleware[]not setOptional. A list of middlewares for processing HTTP requests.
reloadStrategiesReloadStrategy[]not setOptional. The strategies used to reload the worker.
accessLogbooltrueOptional. Whether to log incoming HTTP requests.
gzipboolfalseOptional. Enables gzip compression.
connectionLimitintnot setOptional. The maximum number of connections per worker.
connectionLimitPerIpintnot setOptional. The maximum number of connections allowed per IP.
concurrencyLimitintnot setOptional. The maximum number of concurrent HTTP requests per worker.

⚙️🔌 SymfonyPeriodicProcess

This is the part of Symfony bundle

This worker type is designed to run symfony console commands periodically. The schedule option can be specified in one of the following formats:

  • Number of seconds (e.g. 60)
  • An ISO8601 datetime format (e.g. 2025-01-01 00:00:00)
  • An ISO8601 duration format (e.g. PT1M)
  • A relative date format (e.g. 1 minute)
  • A cron expression (e.g. */1 * * * *)
OptionTypeDefaultDescription
commandstringnot setSymfony console command name.
namestringnot setOptional. The name associated with the worker process.
scheduleint"1 minute"Optional. Schedule in one of the formats described above.
jitterint0Optional. Jitter in seconds that adds a random time offset to the schedule.
userintnot setOptional. Unix user of process. Current user by default.
groupintnot setOptional. Unix group of process. Current group by default.

⚙️🔌 SymfonyWorkerProcess

This is the part of Symfony bundle

This worker type is designed for running long-running symfony console commands.

OptionTypeDefaultDescription
commandstringnot setSymfony console command name.
namestringnot setOptional. The name associated with the worker process.
countint1Optional. The number of processes to start.
reloadablebooltrueOptional. Whether the worker can be reloaded with the reload command.
userstringnot setOptional. Unix user of process. Current user by default.
groupstringnot setOptional. Unix group of process. Current group by default.