diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8276a4d..3035a11 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,12 +9,12 @@ jobs: runs-on: ubuntu-latest container: - image: duyler/php-zts:8.4 + image: duyler/php-zts:8.5 options: --user root strategy: matrix: - php-image: ['duyler/php-zts:8.4'] + php-image: ['duyler/php-zts:8.5'] steps: - name: Checkout @@ -35,7 +35,7 @@ jobs: - name: Update composer run: composer self-update - - name: Install dependencies with composer php 8.4 + - name: Install dependencies with composer php 8.5 run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - name: Run tests with phpunit diff --git a/README.md b/README.md index b8e3503..d361f52 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Process manager with load balancing for Duyler Framework. ## Requirements -- PHP 8.4+ +- PHP 8.5+ - ext-sockets - ext-pcntl - ext-posix @@ -42,52 +42,26 @@ composer require duyler/worker-pool ## Quick Start -### Event-Driven Worker Mode (SharedSocketMaster + Server) +### Event-Driven Worker Mode This is the recommended mode for production HTTP servers. Each worker runs its own event loop with a full `Server` instance. The kernel distributes connections across workers via `SO_REUSEPORT`. ```php use Duyler\HttpServer\Config\ServerConfig; -use Duyler\HttpServer\Server; -use Duyler\HttpServer\ServerInterface; use Duyler\WorkerPool\Config\WorkerPoolConfig; use Duyler\WorkerPool\Master\MasterFactory; use Duyler\WorkerPool\Worker\EventDrivenWorkerInterface; -use Nyholm\Psr7\Response; - -final class MyApp implements EventDrivenWorkerInterface -{ - public function run(int $workerId, ServerInterface $server): void - { - // Do NOT call $server->start(). The master already manages sockets. - // Enable notification for reactive event loop wakeup - $server->enableNotification(); - $notifySocket = $server->getSocketResource(); - - // Polling example (see examples/ for reactive EvIo integration) - while (true) { - if ($server->hasRequest()) { - $requestData = $server->getRequest(); - if ($requestData !== null) { - $response = new Response(200, [], 'Hello from worker ' . $workerId); - $server->respond($requestData->respond($response)); - } - } - usleep(1000); - } - } -} +// Implement EventDrivenWorkerInterface (see Worker Types section for full example) +$worker = new MyApp(); // implements EventDrivenWorkerInterface $serverConfig = new ServerConfig(host: '0.0.0.0', port: 8080); $poolConfig = WorkerPoolConfig::auto($serverConfig); -// MasterFactory automatically picks the best architecture -// and creates the required DI wrappers (SocketWrapper, ForkWrapper, etc.) $master = MasterFactory::createRecommended( config: $poolConfig, serverConfig: $serverConfig, - eventDrivenWorker: new MyApp(), + eventDrivenWorker: $worker, ); $master->start(); // blocks until shutdown diff --git a/composer.json b/composer.json index 33a4280..a5e9623 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ } ], "require": { - "php": "^8.4", + "php": "^8.5", "ext-sockets": "*", "ext-pcntl": "*", "ext-posix": "*",