phpstreamserver / core
PHPStreamServer is a high performance PHP application server
v0.3.0
2024-12-01 15:08 UTC
Requires
- php: >=8.2
- ext-pcntl: *
- ext-posix: *
- amphp/amp: ^3.0.2
- amphp/byte-stream: ^2.1.1
- amphp/socket: ^2.3.1
- psr/container: ^2.0
- psr/log: ^3.0
- revolt/event-loop: ^1.0.6
Suggests
- ext-uv: For better performance
README
PHPStreamServer — PHP Application Server
PHPStreamServer is a high performance, event-loop based application server and process supervisor for PHP written in PHP. As the core component of PHPStreamServer, this module is responsible for comprehensive worker management.
Features
- Worker lifecycle management: Handles the creation, monitoring, and termination of worker processes.
- Automatic restarts: Automatically restarts workers in case of an exception or upon reaching specified limits.
- Time-to-live limits: Sets execution time limits for worker processes.
- Memory usage limits: Set memory usage limits to prevent memory leaks.
- Support for external programs: Use all of these to enable the supervision of external programs and processes.
- Resource sharing across workers: Preload any resources in a master process, and it will be shared among all workers reducing memory usage.
Requirements and limitations
- Unix based OS (no windows support);
- php-posix and php-pcntl extensions;
Install
$ composer require phpstreamserver/core
Configure
Here is an example of a simple supervisor server configuration.
// server.php use PHPStreamServer\Core\Plugin\Supervisor\ExternalProcess; use PHPStreamServer\Core\Plugin\Supervisor\WorkerProcess; use PHPStreamServer\Core\Server; $server = new Server(); $server->addWorker( new WorkerProcess( name: 'Supervised Program', count: 1, onStart: function (WorkerProcess $worker): void { // custom long running process }, ), new ExternalProcess( name: 'External supervised program', count: 1, command: 'sleep 600' ), ); exit($server->run());
Run
$ php server.php start