OpenSwoole\Coroutine\Client->close()

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\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 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...
Last updated on September 20, 2022