OpenSwoole\Coroutine\Http\Client->close

25.x is outdated, please check the latest version 26.x


Latest version: pecl install openswoole-26.2.0

Declaration

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

Parameters

None

Return

When successful true is returned or false if something went wrong.


Description

Close the connection to the remote server.

When trying to use get() or post() OpenSwoole will try and reconnect for you again.


Example

<?php
use OpenSwoole\Coroutine\HTTP\Client;

co::run(function()
{
    $client = new Client('127.0.0.1', 80);

    $client->setHeaders([
        'Host' => "localhost",
        "User-Agent" => 'Chrome/49.0.2587.3',
        'Accept' => 'text/html,application/xhtml+xml,application/xml',
        'Accept-Encoding' => 'gzip',
    ]);

    $client->set(['timeout' => 1]);

    $client->upgrade('/');

    $client->push("websocket data\n");

    var_dump($client->recv());

    $client->close();
});
Last updated on February 28, 2026