undefinedfix
Sign in

Coroutine / client > se t timeout setting problem

blubbafett edited in Sun, 25 Sep 2022

The document is as follows:

The time-out control protocol client provides more fine-grained time-out control. You can set: timeout: total timeout, including connection, sending and receiving all timeouts_ Timeout: connection timeout read_ Timeout: receive timeout write_ Timeout: send timeout

use Swoole ;$ client = new CoroutineClient ( SWOOLE_ SOCK_ TCP );$ client -> set ([

'timeout' => 0.5,
'connect_timeout' => 1.0,
'write_timeout' => 10.0,
'read_timeout' => 0.5,

]);

Could you tell me about timeout and the following three XXX_ What's the relationship between timeout???

1 Replies
Fastful
commented on Mon, 26 Sep 2022

You can see from the source code

swoole_ client_ coro.cc :

bool php_swoole_client_set(Socket *cli, zval *zset)
{
    HashTable *vht = Z_ARRVAL_P(zset);
    zval *ztmp;
    bool ret = true;

    /**
     * timeout
     */
    if (php_swoole_array_get_value(vht, "timeout", ztmp))
    {
        cli->set_timeout(zval_get_double(ztmp));
    }
    if (php_swoole_array_get_value(vht, "connect_timeout", ztmp))
    {
        cli->set_timeout(zval_get_double(ztmp), SW_TIMEOUT_CONNECT);
    }
    if (php_swoole_array_get_value(vht, "read_timeout", ztmp))
    {
        cli->set_timeout(zval_get_double(ztmp), SW_TIMEOUT_READ);
    }
    if (php_swoole_array_get_value(vht, "write_timeout", ztmp))
    {
        cli->set_timeout(zval_get_double(ztmp), SW_TIMEOUT_WRITE);
    }
    // 省略……
}

include\coroutine_ socket.h:

    /* set connect read write timeout */
    inline void 
    set_timeout(double timeout, int type = SW_TIMEOUT_ALL)
    {
        if (timeout == 0)
        {
            return;
        }
        if (type & SW_TIMEOUT_CONNECT)
        {
            connect_timeout = timeout;
        }
        if (type & SW_TIMEOUT_READ)
        {
            read_timeout = timeout;
        }
        if (type & SW_TIMEOUT_WRITE)
        {
            write_timeout = timeout;
        }
    }

Setting timeout will make connect_ timeout、read_ timeout、write_ The timeout is all set to the same value. You can then set the timeout for an operation separately.

lock This question has been locked and the reply function has been disabled.