Swoole\Coroutine\Client->close()

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


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Coroutine\Client->close(): bool

Parameters

None

Return

Returns true if successful and false if not.

Description

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.

Example

<?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...
Last updated on August 31, 2022