Swoole Server close

4.x is outdated, please check the latest version 22.x

Latest version: pecl install openswoole-22.1.2


<?php Swoole\Server->close(int $fd, bool $force = false): bool



The file descriptor you want to close


Setting to true forces the connection to close, losing any data, the default (false) will wait for any data to be transmitted



If success, it returns 'true', otherwise it returns false.

Close the connection to the remote TCP socket and trigger the onClose event. You can force the connection to close but any data in transit will be lost, so the default is to wait for data to be sent.

Closing a connection triggers the onClose callback where you can perform any cleanup tasks, don't do any cleanup elsewhere.

You can get the $fd from the server when the client connects.


$server->on('request', function ($request, $response) use ($server)
Last updated on August 31, 2022