我设置了CURLOPT_CONNECTTIMEOUT_MS = 200和CURLOPT_TIMEOUT_MS = 70 ms.但是我看到CURLINFO_TOTAL_TIME大约是220毫秒.
根据libcurl doc,CURLOPT_TIMEOUT_MS也包括连接超时.所以基本上我的卷曲呼叫总时间不应超过70毫秒.但为什么它会更多地回归控制权呢?
有人可以解释一下这种行为.
我正在使用curl 7.19_02 C++库.
这是我的代码
CURL * curl;
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl,CURLOPT_CONNECTTIMEOUT_MS,200);
curl_easy_setopt(curl,CURLOPT_TIMEOUT_MS,70);
curl_easy_setopt(curl, CURLOPT_HEADER, 0);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
double tt = 0.0;
double ns = 0.0;
double ct = 0.0;
double pt = 0.0;
double st = 0.0;
curl_easy_perform(curl);
int curlRC = curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &tt);
curlRC = curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &ns);
curlRC = curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &ct);
curlRC = curl_easy_getinfo(curl, CURLINFO_PRETRANSFER_TIME, &pt);
curlRC = curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, &st);
cout << "Curl timing info: Total: " << tt << endl << " Lookup: "<< ns << endl << " Connect: " << ct << "\n" << "pre transfer: " << pt << endl << "start transfer: " << st <<endl;
Run Code Online (Sandbox Code Playgroud)
我得到的时间信息如下.请检查一下
卷曲时间信息:总计:0.216793
查询:0.000999
连接:0.023199
预转:0.023213
开始转移:0.216667
那么关键是,预转移和开始转移之间发生了什么?
那么问题来了,预传输和开始传输之间发生了什么?
这是服务器计算结果(处理您的请求)并准备发送响应的第一个字节所花费的实际时间。简而言之,这是请求的实际服务器时间,您会期望这是最大的部分