Conveyor Server Events
“Each part responds to the events with precision, creating a harmonious and responsive system.”
–
Conveyor Server comes with events that you can add listeners to and customize the whole mechanism. Here is the list of events:
Conveyor\ConveyorServer::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:
<?php
namespace Conveyor\Events;
use OpenSwoole\WebSocket\Server;
class PreServerStartEvent
{
public function __construct(
public Server $server,
) {
}
}
Conveyor\ConveyorServer::EVENT_SERVER_STARTED
This event happens after the server has started. The listener will receive an instance of the following class as input:
<?php
namespace Conveyor\Events;
use OpenSwoole\WebSocket\Server;
class ServerStartedEvent
{
public function __construct(
public Server $server,
) {
}
}
Conveyor\ConveyorServer::EVENT_PRE_SERVER_RELOAD
This event happens before the server reloads. The listener will receive an instance of the following class as input:
<?php
namespace Conveyor\Events;
use OpenSwoole\WebSocket\Server;
class PreServerReloadEvent
{
public function __construct(
public Server $server,
) {
}
}
Conveyor\ConveyorServer::EVENT_POST_SERVER_RELOAD
This event happens after the server reloads. The listener will receive an instance of the following class as input:
<?php
namespace Conveyor\Events;
use OpenSwoole\WebSocket\Server;
class PostServerReloadEvent
{
public function __construct(
public Server $server,
) {
}
}
Conveyor\ConveyorServer::EVENT_MESSAGE_RECEIVED
This event happens whenever a message is received. The listener will receive an instance of the following class as input:
<?php
namespace Conveyor\Events;
use OpenSwoole\WebSocket\Server;
class MessageReceivedEvent
{
public function __construct(
public Server $server,
public string $data,
) {
}
}
Conveyor\ConveyorServer::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:
<?php
namespace Conveyor\Events;
use OpenSwoole\WebSocket\Server;
class BeforeMessageHandledEvent
{
public function __construct(
public Server $server,
public string $data,
public int $fd,
) {
}
}
Conveyor\ConveyorServer::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:
<?php
namespace Conveyor\Events;
use OpenSwoole\WebSocket\Server;
class AfterMessageHandledEvent
{
public function __construct(
public Server $server,
public string $data,
public int $fd,
) {
}
}