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\Plugin\Supervisor\WorkerProcess;
use PHPStreamServer\Core\Server;
use PHPStreamServer\Plugin\HttpServer\HttpServerPlugin;

$server = new Server(
// Server-level configuration
);

$server->addPlugin(
new HttpServerPlugin(
// Plugin-level configuration
),
);

$server->addWorker(
new WorkerProcess(
// Worker-level configuration
),
);

Server-level 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-level configuration

Each plugin has its own specific configuration. See the Plugins page for more details.
Plugins can be added to the server using the Server::addPlugin() method.

Worker-level 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.

Reload strategies in PHPStreamServer define the rules for when workers should be restarted. PHPStreamServer provides several built-in reload strategies of the box. Additionally, plugins can add new reload strategies, enhancing functionality.

⚙️ WorkerProcess

This worker type is designed for running long-running PHP code.

OptionTypeDefaultDescription
namestring"none"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.
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
namestring"none"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.
commandstringnot setThe external command or script to execute.

🔄️ TTLReloadStrategy

Reloads a worker after a specified time-to-live (TTL) interval. This ensures that workers are periodically restarted, which can help prevent issues caused by long-running processes.

OptionTypeDefaultDescription
ttlintnot setTime-to-live interval in seconds.

🔄️ MaxMemoryReloadStrategy

Reloads a worker when its memory consumption exceeds a specified threshold. This helps manage memory leaks and prevents excessive memory usage.

OptionTypeDefaultDescription
maxMemoryintnot setMemory consumption threshold in bytes.

🔄️ ExceptionReloadStrategy

Reloads a worker when an exception is thrown, except for specified exceptions that are excluded from triggering a reload. This ensures workers don't 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.