onWorkerReload

Requirement (workerman >= 3.2.5)

Description:

callback Worker::$onWorkerReload

This feature is not frequently used.

Sets the callback to be executed when the Worker receives a reload signal.

You can use the onWorkerReload callback to perform various tasks, such as reloading business configuration files without the need to restart the process.

Note:

The default action for child processes receiving a reload signal is to exit and restart, so that the new process can reload the business code to complete the code update. Therefore, it is normal for the child process to immediately exit after executing the onWorkerReload callback following a reload.

If you only want the child process to execute onWorkerReload and do not want it to exit after receiving the reload signal, you can set the corresponding Worker instance's reloadable property to false when initializing the Worker instance.

Callback Function Parameter

$worker

Which is the Worker object

Example

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

$worker = new Worker('websocket://0.0.0.0:8484');
// Set reloadable to false, meaning child processes do not execute restart upon receiving reload signals
$worker->reloadable = false;
// Notify all clients that the server has executed a reload after reload
$worker->onWorkerReload = function(Worker $worker)
{
    foreach($worker->connections as $connection)
    {
        $connection->send('worker reloading');
    }
};
// Run the worker
Worker::runAll();

Tip: In addition to using an anonymous function as a callback, you can also refer here for other callback styles.