Why would CURL time out in 1000ms when I have set up timeout upto 3000ms?
In one of my script I have set up curl time out, CURLOPT_CONNECTTIMEOUT_MS, to 3000ms, but curl time outs muc开发者_如何转开发h before than that, at an average of 1000ms. Why would it time out so early?
I believe the timeout you are seeing is a CURL operation timeout, rather than a connection timeout. These two are different.
CURLOPT_TIMEOUT
(and CURLOPT_TIMEOUT_MS
for millisecond values) control the timeout for the work CURL does after it's connected. CUROPT_CONNECTTIMEOUT
(and CUROPT_CONNECTTIMEOUT_MS
) control the timeout for the initial connection (DNS lookup, establishing the connection, etc.)
If I'm right, then if you set CURLOPT_TIMEOUT higher than 1, you should find that your timeout doesn't trip at 1000ms any more.
Check the version of your CURL and PHP installation. CURLOPT_CONNECTTIMEOUT_MS added in cURL 7.16.2. Available since PHP 5.2.3. http://php.net/manual/en/function.curl-setopt.php
精彩评论