【问题标题】:curl req1 and rea2 same curl handle for CURLOPT_CONNECTTIMEOUT + CURLOPT_TIMEOUT issue ....curl req1 和 rea2 相同的 curl 句柄用于 CURLOPT_CONNECTTIMEOUT + CURLOPT_TIMEOUT 问题 ....
【发布时间】:2016-02-18 13:22:53
【问题描述】:

curll_handle = 卷曲初始化()

curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 20 )
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);

请求1:(curll_handle)

Curl_easy_perform(curll_handle)
For connection = 20 secs
Chal response request = 30 secs

request2:与上面使用的句柄相同

curl_slist_append(headers, "Connection: Close");

Curl_easy_perform(curll_handle)

问题:

Request 1:
    will it use both timeouts(connection and response timeouts) for curl perform?
    what is the total time will take? as per my understand 30 secs(CURLOPT_CONNECTTIMEOUT + CURLOPT_TIMEOUT)

Request 2:
    if we use same request1 curl handle for request2. is it(req2) curl_easy_perform() will d0 both connection and response sequence requestS?
    what the timeout value use for sencond request if use same req1 curl handle? 

【问题讨论】:

    标签: libcurl


    【解决方案1】:

    请求 1:

    CURLOPT_TIMEOUT 是整个操作的最长时间。它不会花费更多时间。你知道它会在 30 秒内完成,无论成功与否。

    CURLOPT_CONNECTTIMEOUT 是您允许“连接阶段”花费的最长时间。如果在 20 秒内没有连接到远程服务器,传输将返回失败。

    时间设置完全相互独立。因此,如果连接阶段需要 19 秒,则还有 11 秒等待传输完成,否则将触发最大超时。

    请求 2:

    使用相同的选项并且选项是粘性的,并且在更改之前都是相同的,因此它将具有与请求 1 完全相同的超时值。

    如果从请求 1 中保留并重新使用连接,CURLOPT_CONNECTTIMEOUT 将不会触发,因为它已经连接。

    【讨论】:

    • 嗨,由于 request-2 使用来自 request-1 的持久连接,CURLOPT_CONNECTTIMEOUT 在 request-2 中真的很重要吗?
    • 好吧,我现在修改了我的答案以包含那个细节!
    猜你喜欢
    • 2011-04-16
    • 2011-05-31
    • 2015-07-24
    • 2018-09-24
    • 1970-01-01
    • 2012-06-01
    • 2011-09-21
    • 1970-01-01
    • 2012-07-27
    相关资源
    最近更新 更多