Conveyor Server Events

Conveyor dispatches server events so you can observe lifecycle, HTTP, task, and message handling behavior.


Register listeners

Pass listeners when creating the server:

1<?php
2
3use Conveyor\Constants;
4use Conveyor\ConveyorServer;
5use Conveyor\Events\MessageReceivedEvent;
6
7require __DIR__ . '/vendor/autoload.php';
8
9(new ConveyorServer())
10    ->eventListeners([
11        Constants::EVENT_MESSAGE_RECEIVED => function (MessageReceivedEvent $event) {
12            var_dump($event->data);
13        },
14    ])
15    ->port(8989)
16    ->start();

Lifecycle events

Constants::EVENT_PRE_SERVER_START

Receives Conveyor\Events\PreServerStartEvent:

1public function __construct(public Server $server)

Constants::EVENT_SERVER_STARTED

Receives Conveyor\Events\ServerStartedEvent:

1public function __construct(public Server $server)

Constants::EVENT_SERVER_CLOSE

Receives Conveyor\Events\ConnectionCloseEvent:

1public function __construct(public Server $server, public int $fd)

Message events

Constants::EVENT_MESSAGE_RECEIVED

Receives Conveyor\Events\MessageReceivedEvent:

1public function __construct(
2    public Server $server,
3    public string $data,
4    public int $taskId,
5    public int $reactorId,
6)

Constants::EVENT_BEFORE_MESSAGE_HANDLED

Receives Conveyor\Events\BeforeMessageHandledEvent:

1public function __construct(
2    public Server $server,
3    public string $data,
4    public int $fd,
5)

Constants::EVENT_AFTER_MESSAGE_HANDLED

Receives Conveyor\Events\AfterMessageHandledEvent:

1public function __construct(
2    public Server $server,
3    public string $data,
4    public int $fd,
5)

HTTP and task events

Constants::EVENT_REQUEST_RECEIVED

Receives Conveyor\Events\RequestReceivedEvent:

1public function __construct(
2    public Request $request,
3    public Response $response,
4)

Constants::EVENT_TASK_FINISHED

Receives Conveyor\Events\TaskFinishedEvent:

1public function __construct(
2    public Server $server,
3    public string $data,
4    public int $taskId,
5)

Use HTTP Requests for the built-in native and Pusher-compatible endpoints before adding custom request behavior.