<?php
Swoole\Server->on('close', callback $callback)
The event name
callback function
if success, it returns TRUE, otherwise it returns FALSE.
Executue the callback function when the Server is closing a new connection.
<?php
function (Swoole\Server $server, int $fd, int $reactorId) {
}
$server
the swoole server object$fd
the id number of client$reactorId
the id number of reactor thread, when the $reactorId
< 0, the connection is closed by server.<?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();