swoole_server->close
�رտͻ������ӣ�����ԭ�ͣ�
bool swoole_server->close(int $fd, bool $reset = false);
swoole-1.8.0����߰汾����ʹ������$reset����
- �����ɹ�����true��ʧ�ܷ���false.
- Server����close���ӣ�Ҳһ���ᴥ��onClose�¼���
- ��Ҫ��close֮��д��������Ӧ�����õ�onClose�ص��д���
- $reset����Ϊtrue��ǿ�ƹر����ӣ��������Ͷ����е�����
���ӣ�
<?php $serv = new swoole_server("0.0.0.0", 9501); $serv->set(array( 'worker_num' => 2, 'dispatch_mode' => 3, 'daemonize' => false, 'log_file' => '/tmp/swoole.log' )); $serv->on('start', function($serv) { echo 'start',PHP_EOL; }); $serv->on('workerStart', function($serv, $worker_id) { echo "server start\n"; }); $serv->on('connect', function ($serv, $fd, $from_id){ echo "[#".posix_getpid()."]\tClient@[$fd:$from_id]: Connect.\n"; }); $serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) { echo "[#".$serv->worker_id."]\tClient[$fd]: $data\n"; $serv->send($fd, json_encode(array("hello" => '1213', "bat" => "ab")).PHP_EOL); $serv->close($fd); }); $serv->on('close', function ($serv, $fd, $from_id) { echo "[#".posix_getpid()."]\tClient@[$fd:$from_id]: Close.\n"; }); $serv->start();