curl req1 and rea2 same curl handle for CURLOPT_CONNECTTIMEOUT + CURLOPT_TIMEOUT issue …

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 05:08:31

问题


curll_handle = Curl init()

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

Request1:(curll_handle)

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

request2:same handle used as above

curl_slist_append(headers, "Connection: Close");

Curl_easy_perform(curll_handle)

Questions:

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? 

回答1:


Request 1:

CURLOPT_TIMEOUT is the maximum time for the entire operation. It will not spend more time. You know it will be done within 30 seconds, successful or not.

CURLOPT_CONNECTTIMEOUT is the longest time you allow the "connection phase" to take. If the connection to the remote server is not done within 20 seconds, the transfer will return failure.

The times are set totally independent of each other. So if the connection phase takes 19 seconds, there is 11 seconds left for the transfer to complete or the maximum timeout will trigger.

Request 2:

Uses the same options and options are sticky and will be the same until changed, so it will have the exact same timeout values as request 1.

If the connection is kept and re-used from request 1, the CURLOPT_CONNECTTIMEOUT won't trigger since it is already connected.



来源:https://stackoverflow.com/questions/35482680/curl-req1-and-rea2-same-curl-handle-for-curlopt-connecttimeout-curlopt-timeout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!