luzrain / phpstreamserver
There is no license information available for the latest version (v123) of this package.
PHPStreamServer
v123
2024-11-20 15:49 UTC
Requires
- php: >=8.2
- ext-pcntl: *
- ext-posix: *
- amphp/amp: ^3.0.2
- amphp/byte-stream: ^2.1.1
- amphp/http-server: ^3.3.1
- amphp/socket: ^2.3.1
- dragonmantank/cron-expression: ^3.4
- luzrain/polyfill-inotify: ^1.0
- promphp/prometheus_client_php: ^2.12
- psr/container: ^2.0
- psr/http-message: ^2.0
- psr/log: ^3.0
- revolt/event-loop: ^1.0.6
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.60.0
- guzzlehttp/guzzle: ^7.9.2
- phpunit/phpunit: ^10.5.28
- psalm/phar: ^5.25
- symfony/var-dumper: ^6.4.10
- symplify/monorepo-builder: ^11.2
Replaces
- luzrain/phpstreamserver: v123
- phpstreamserver/filemonitor-plugin: v123
- phpstreamserver/httpserver-plugin: v123
- phpstreamserver/logger-plugin: v123
- phpstreamserver/metrics-plugin: v123
- phpstreamserver/scheduler-plugin: v123
This package is auto-updated.
Last update: 2024-11-20 18:44:06 UTC
README
PHPStreamServer - PHP Application Server
Note
This package is now under development
PHPStreamServer is a high performance event-loop based process manager, scheduler and webserver written in PHP. This application server is designed to replace traditional setup for running php applications such as nginx, php-fpm, cron, supervisor.
Key features:
- Process manager;
- Scheduler;
- Workers lifecycle management (reload by TTL, max memory, max requests, on exception, on each request);
- HTTP/2
Requirements and limitations:
- Unix based OS (no windows support);
- php-posix and php-pcntl extensions;
- php-uv extension is not required, but recommended for better performance.
Getting started
Install composer packages
$ composer require luzrain/phpstreamserver
Configure server
Here is example of simple http server.
// server.php use Amp\Http\Server\HttpErrorException;use Amp\Http\Server\Request;use Amp\Http\Server\Response;use PHPStreamServer\BundledPlugin\HttpServer\HttpServerPlugin;use PHPStreamServer\BundledPlugin\HttpServer\HttpServerProcess;use PHPStreamServer\BundledPlugin\Scheduler\PeriodicProcess;use PHPStreamServer\BundledPlugin\Scheduler\SchedulerPlugin;use PHPStreamServer\Plugin\Supervisor\WorkerProcess;use PHPStreamServer\Server; $server = new Server(); $server->addPlugin( new HttpServerPlugin(), new SchedulerPlugin(), ); $server->addWorker( new HttpServerProcess( name: 'Web Server', count: 1, listen: '0.0.0.0:8088', onStart: function (HttpServerProcess $worker, mixed &$context): void { // initialization }, onRequest: function (Request $request, mixed &$context): Response { return match ($request->getUri()->getPath()) { '/' => new Response(body: 'Hello world'), '/ping' => new Response(body: 'pong'), default => throw new HttpErrorException(404), }; } ), new WorkerProcess( name: 'Supervised Program', count: 1, onStart: function (WorkerProcess $worker): void { // custom long running process }, ), new PeriodicProcess( name: 'Scheduled program', schedule: '*/1 * * * *', onStart: function (PeriodicProcess $worker): void { // runs every 1 minute }, ), ); exit($server->run());
Run
$ php server.php start