Skip to main content

Configuration

PHPStreamServer allows you to define settings at various levels of the application.
Configurations can be applied in the Server, Plugin, or Worker constructors.
It is recommended to use named parameters when specifying 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 impact all workers.

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

Plugin Configuration

Plugin-level configuration defines settings specific to individual plugins. See the plugins documentation for detailed options and examples.
Read more →

Worker Configuration

Worker-level configuration applies to individual workers, allowing you to control their specific behavior. PHPStreamServer includes several built-in worker types, and plugins can add additional worker types to extend functionality.
Additional worker types are available through plugins.
Read more →

⚙️ WorkerProcess

Worker class: WorkerProcess
This worker type is designed to run 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

Worker class: ExternalProcess
This worker type is designed to run external processes, allowing PHPStreamServer to manage and supervise programs or scripts 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.

Reload Strategies

Reload strategies in PHPStreamServer define the rules that determine when workers should be restarted. PHPStreamServer provides several built-in reload strategies out of the box, and plugins can add new ones.
Additional reload strategies are available through plugins.
Read more →

🔄️ TTLReloadStrategy

Reload strategy class: TTLReloadStrategy
Reloads a worker after a specified time-to-live (TTL) interval. This periodic restart helps prevent potential issues caused by long-running processes.

OptionTypeDefaultDescription
ttlintnot setTime-to-live interval in seconds.

🔄️ MaxMemoryReloadStrategy

Reload strategy class: MaxMemoryReloadStrategy
Reloads a worker when its memory usage exceeds a specified threshold. This helps control memory leaks and prevents excessive memory consumption.

OptionTypeDefaultDescription
maxMemoryintnot setMemory consumption threshold in bytes.

🔄️ ExceptionReloadStrategy

Reload strategy class: ExceptionReloadStrategy
Reloads a worker when an exception is thrown, except for those explicitly excluded from triggering a reload. This ensures that workers do not remain in an unexpected state after encountering an error.

OptionTypeDefaultDescription
allowedExceptionsclass-string[]not setOptional. A list of exception class names that will not trigger a reload.