callback Worker::$onWorkerStart

Sets the callback function for when a Worker sub-process starts, which gets executed each time a sub-process starts.

Note: onWorkerStart runs when a child process starts, if multiple child processes ($worker->count > 1) are enabled, the callback will run $worker->count times in total.

Callback Function Parameters


Refers to the Worker object.


use Workerman\Worker;
require_once __DIR__ . '/vendor/autoload.php';

$worker = new Worker('websocket://');
$worker->onWorkerStart = function(Worker $worker)
    echo "Worker starting...\n";
// Run the worker

Note: Apart from using anonymous functions as callbacks, you can also refer to here for other callback styles.