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

Latest version: pecl install openswoole-22.1.2


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




Returns true when the client is connected to the server and false when the client is not currently connected to the server


Check if the client connection is currently established and not disconnected.

This method returns the status of the connection on an application layer basis, meaning it is the status of if connect() has been performed successfully or not. Once you have called connect() successfully it cannot be called again, this would result in an error, you must close a connection first. However, the connection status from isConnected() is purely at the application level, this is not the actual TCP state. Errors can still appear when sending or receiving data via the client even if the isConnected() method returns true as something might have happened between that time and when data is sent or received. You don't truly know if a connection is available or not until you try to send or receive data, as that is a kernel operation.



use Swoole\Coroutine\Client;

    $client = new Client(SWOOLE_SOCK_TCP);

    if(!$client->connect('', 9501, 0.5))
        echo "Connection failed with error: {$client->errCode}\n";

    // Should not rely on this 100%, see description as to why
    if($client->isConnected() === false)
        echo "Connection failed with error: {$client->errCode}\n";

    $client->send("Hello World! - from Swoole\n");

    echo $client->recv();

Last updated on August 31, 2022