Core concepts

Conveyor Server Events

“Each part responds to the events with precision, creating a harmonious and responsive system.”


Table of Contents

Overview

Conveyor Server comes with events that you can add listeners to and customize the whole mechanism.

To understand how to add listeners to these events, visit this page.

Here is the list of events:

Server Start

Conveyor\Constants::EVENT_PRE_SERVER_START

This event happens before the server starts. This can be used to handle HTTP connections or to customize other server events. To know more, check: Handling HTTP Requests.

The listener will receive an instance of the following class as input:

1<?php
2
3namespace Conveyor\Events;
4
5use OpenSwoole\WebSocket\Server;
6
7class PreServerStartEvent
8{
9    public function __construct(
10        public Server $server,
11    ) {
12    }
13}

Server Started

Conveyor\Constants::EVENT_SERVER_STARTED

This event happens after the server has started. The listener will receive an instance of the following class as input:

1<?php
2
3namespace Conveyor\Events;
4
5use OpenSwoole\WebSocket\Server;
6
7class ServerStartedEvent
8{
9    public function __construct(
10        public Server $server,
11    ) {
12    }
13}

Server Reload

Conveyor\Constants::EVENT_PRE_SERVER_RELOAD

This event happens before the server reloads. The listener will receive an instance of the following class as input:

1<?php
2
3namespace Conveyor\Events;
4
5use OpenSwoole\WebSocket\Server;
6
7class PreServerReloadEvent
8{
9    public function __construct(
10        public Server $server,
11    ) {
12    }
13}

Post Server Reload

Conveyor\Constants::EVENT_POST_SERVER_RELOAD

This event happens after the server reloads. The listener will receive an instance of the following class as input:

1<?php
2
3namespace Conveyor\Events;
4
5use OpenSwoole\WebSocket\Server;
6
7class PostServerReloadEvent
8{
9    public function __construct(
10        public Server $server,
11    ) {
12    }
13}

Message Received

Conveyor\Constants::EVENT_MESSAGE_RECEIVED

This event happens whenever a message is received. The listener will receive an instance of the following class as input:

1<?php
2
3namespace Conveyor\Events;
4
5use OpenSwoole\WebSocket\Server;
6
7class MessageReceivedEvent
8{
9    public function __construct(
10        public Server $server,
11        public string $data,
12    ) {
13    }
14}

Before Message Handled

Conveyor\Constants::EVENT_BEFORE_MESSAGE_HANDLED

This event happens before a received message is handled. The listener will receive an instance of the following class as input:

1<?php
2
3namespace Conveyor\Events;
4
5use OpenSwoole\WebSocket\Server;
6
7class BeforeMessageHandledEvent
8{
9    public function __construct(
10        public Server $server,
11        public string $data,
12        public int $fd,
13    ) {
14    }
15}

After Message Handled

Conveyor\Constants::EVENT_AFTER_MESSAGE_HANDLED

This event happens when a received message is handled. The listener will receive an instance of the following class as input:

1<?php
2
3namespace Conveyor\Events;
4
5use OpenSwoole\WebSocket\Server;
6
7class AfterMessageHandledEvent
8{
9    public function __construct(
10        public Server $server,
11        public string $data,
12        public int $fd,
13    ) {
14    }
15}
Previous
HTTP Requests