Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\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.
<?php
$server->on('request', function ($request, $response) use ($server)
{
$server->close($response->fd);
});