The function prototype

@param \EasySwoole\EasySwoole\Swoole\EventRegister $register
public static function mainServerCreate(EventRegister $register)

Finished work

At the time of executing the event, the following work has been completed:

  • Framework initializes events
  • The configuration file is loaded
  • The main Swoole Server is created successfully
  • Main Swoole Server registered its default onRequest, onTask, onFinish events.。

Processable content

Register the main service callback event

For example, register the onWorkerStart event for the main service

$register->add($register::onWorkerStart,function (\swoole_server $server,int $workerId){

For example, add an onMessage event to the main service

  // In WebSocket mode message events must be registered and handed in 
$register->set(EventRegister::onMessage, function (\swoole_websocket_server $server, \swoole_websocket_frame $frame) {

The set method is different from the add method. The set method overrides the previously configured event callback, while the add method adds a new callback

Add a custom process

Detailed operations can be viewed in the basic use -> custom process

\EasySwoole\Component\Process\Manager::getInstance()->addProcess(new Test('test_process'));

Test is a subclass of the EasySwoole\Component\Process\AbstractProcess'abstract class

Add a subservice listener

$subPort = ServerManager::getInstance()->getSwooleServer()->addListener('',9503,SWOOLE_TCP);
$subPort->on('receive',function (\swoole_server $server, int $fd, int $reactor_id, string $data){

Refer to different ways of writing Demo branches event: The demo branch

Call the coroutine API before starting

use Swoole\Coroutine\Scheduler;
$scheduler = new Scheduler();
$scheduler->add(function() {
    /*  Call the coroutine API */
//Clear all timers