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\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 OpenSwoole\Coroutine\Client(OpenSwoole\Constant::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...