Swoole\Server->on('start', fn)


Swoole\Server->on('start', callback $callback)



The event name


callback function



if success, it returns TRUE, otherwise it returns FALSE.


Executue the callback function when the Server is started.

Before the start stage, the Server has finished the stages:

  • Create the Manager Process
  • Create the Worker Processes
  • Listen on the TCP/UDP port
  • Started the Swoole Timer

After the start stage, the reactor threads are ready to process event and accept connections.

In the callback function registered on start, only limited functions should be defined. Such as logging, record and modify the name of process, record the process ID etc .

The stages start and workerstart are started the same time in different processes.

It is recommended to save the value of $server->master_pid and $server->manager_pid into file in the start callback function. Then you are able to send Linux signals to control these processes.

This stage can't be used in SWOOLE_BASE mode.


$server = new Swoole\Server("", 9501);
$server->on('start', function ($server){
    echo "Server is started.\n";
$server->on('connect', function ($server, $fd){
    echo "New connection established: #{$fd}.\n";
$server->on('receive', function ($server, $fd, $from_id, $data) {
    $server->send($fd, "Echo to #{$fd}: \n".$data);
$server->on('close', function ($server, $fd) {
    echo "Connection closed: #{$fd}.\n";