Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
36 changes: 5 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"php": "^8.4",
"php": "^8.5",
"ext-sockets": "*",
"ext-pcntl": "*",
"ext-posix": "*",
Expand Down
Loading