cURL really slow

后端 未结 2 1071
萌比男神i
萌比男神i 2021-01-12 03:02

Does anybody know why could cURL under php5 be so damn slow to fail even at 45s timeout, downloading a few kb file on a speedO\'light server?

The code is here as req

2条回答
  •  悲&欢浪女
    2021-01-12 03:51

    hmm, could be a few things, maybe some verbose output will have an error of some kind

    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    curl_setopt($ch, CURLOPT_VERBOSE, true); // some output will go to stderr / error_log
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    $response = curl_exec($ch);
    $errStr = curl_error($ch);
    $errNum = curl_errno($ch);
    $head = curl_getinfo($ch, CURLINFO_HEADER_OUT);
    $ci = curl_getinfo($ch);
    print_r(array($head, $errStr, $errNum, $ci));
    

    Sometimes the user agent will change how a site responds, may need to do something like:

    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101');
    

提交回复
热议问题