workerman
workerman copied to clipboard
How detect stop server event ?
I want to listen for a server stop event to take an action if this happens
Use Worker::$onMasterStop like this.
Worker::$onMasterStop = function(){
echo 'stoped';
};
I tried it from php but it doesn't execute anything, I think what you give me is focused on javascript or I'm wrong
test.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Protocols\Http\Request;
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
Worker::$onMasterStop = function () {
echo "stoped\n";
};
$worker = new Worker('http://127.0.0.1:1234');
$worker->onMessage = function (TcpConnection $connection, Request $request) {
$connection->send('hello');
};
Worker::runAll();
Run command php start.php start.

Run command php start.php stop in another console.

The first console printed 'stoped'

Thank you very much, do you know if there is any way to automatically initialize the server if it stops due to an error or for any reason?