<?php
Swoole\Server->on('shutdown', callback $callback)
The event name
callback function
if success, it returns TRUE, otherwise it returns FALSE.
Executue the callback function when the Server is shuttng down.
Before the stage shutdown
started, these steps are finished:
Force killing a process using
kill -9
, doesn't trigger the callback function onshutdown
. Use signalSIGTREM
andkill -15
instead.
<?php
$server = new Swoole\Server("127.0.0.1", 9501);
$server->on('start', function ($server){
echo "Server is started.\n";
});
$server->on('shutdown', function ($server){
echo "Server is shuttng down.\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->close($fd);
});
$server->on('close', function ($server, $fd) {
echo "Connection closed: #{$fd}.\n";
});
$server->start();