Swoole Server close

Declaration

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

Parameters

fd

The file descriptor you want to close

force

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

Return

success

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.

Example

<?php
$server->on('request', function ($request, $response) use ($server)
{
    $server->close($response->fd);
});