Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Coroutine\Client->close(): bool
None
Returns true
if successful and false
if not.
Close the socket connection. Calling this function will not block the process, it returns immediately, there is no coroutine switch when closing a connection. Once a connection has been closed, you are able to connect to another server again.
<?php
$client = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP);
if(!$client->connect('127.0.0.1', 9501, 0.5))
{
exit("Connection Failed. Error: {$client->errCode}\n");
}
$client->send("Hello World!\n");
echo $client->recv();
// Close the connection
$client->close();
// You can reconnect again after this...