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

Declaration

<?php
Swoole\Server->on('ManagerStart', Callable $callback)

Parameters

event

The event callback name.

callback

Callable event function.

Return

success

If success, it returns true, otherwise it returns false.

Description

Execute the callback function when the Manager Process in the Server is started.

The callback function registered for the event ManagerStart is executed in the manager process.

You can alter the name of this process within the callback function and you may use the server sendMessage function to communicate with other worker processes.

At this stage when this callback is executed, all worker and task worker processes have been started but the status of the Master process is still unknown because both the Master and Manager threads are executed concurrently, so either one could complete at the same time.

If running a server using SWOOLE_BASE mode and if worker_num, max_request and task_worker_num configuration parameters have been set, Swoole will create the manager processes to act as worker processes, which in return will trigger the ManagerStart and ManagerStop server events, it is more recommended to use SWOOLE_PROCESS mode.

Example

<?php
$server->on('ManagerStart', function(Swoole\Server $server)
{
  // ...
});