File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -24,16 +24,16 @@ $server = new Server();
2424
2525$server->addPlugin(
2626 new HttpServerPlugin(
27- // HttpServerPlugin configuration
27+ // Optional. HttpServerPlugin configuration
2828 ),
2929);
3030
3131$server->addWorker(
3232 new HttpServerProcess(
3333 // HttpServerProcess configuration
34- name: 'Web Server',
35- count: 2,
36- listen: '0.0.0.0:8080',
34+ name: 'Web Server', // Worker name
35+ listen: '0.0.0.0:8080', // Address to listen on
36+ count: 2, // Number of worker processes
3737 onRequest: function (Request $request, HttpServerProcess $worker): Response {
3838 return match ($request->getUri()->getPath()) {
3939 '/' => new Response(body: 'Hello world'),
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ use PHPStreamServer\Core\Server;
1616use PHPStreamServer\Core\Worker\WorkerProcess;
1717use PHPStreamServer\Plugin\Logger\Handler\ConsoleHandler;
1818use PHPStreamServer\Plugin\Logger\LoggerPlugin;
19+ use Psr\Log\LoggerInterface;
1920
2021$server = new Server();
2122
@@ -29,7 +30,11 @@ $server->addWorker(
2930 new WorkerProcess(
3031 name: 'Worker process',
3132 onStart: function (WorkerProcess $worker): void {
32- $worker->logger->info('Hello from worker', ['pid' => \posix_getpid()]);
33+ $logger = $worker->container->getService(LoggerInterface::class);
34+ $logger->info('Hello from worker', ['pid' => \posix_getpid()]);
35+
36+ // You can also use the logger like this:
37+ // $worker->logger->info('Hello from worker', ['pid' => \posix_getpid()]);
3338 },
3439 ),
3540);
You can’t perform that action at this time.
0 commit comments