newbtophp Posted November 12, 2009 Share Posted November 12, 2009 I need some help please, I have some code like: $ch = curl_init(); // initialize curl handle curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)"); curl_setopt($ch, CURLOPT_AUTOREFERER, false); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,7); curl_setopt($ch, CURLOPT_REFERER, 'http://site.com/upload/'); curl_setopt($ch, CURLOPT_URL,$url); // set url to post to curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable curl_setopt($ch, CURLOPT_TIMEOUT, 60); // times out after 60s curl_setopt($ch, CURLOPT_POST, 1); // set POST method curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); // add POST fields $buffer = curl_exec($ch); // run the whole process curl_close($ch); I want to echo some text if the curl takes over 60 seconds to respond (from the other site). :-\ Quote Link to comment https://forums.phpfreaks.com/topic/181259-if-curl-takes-60-seconds-then-echo-error/ Share on other sites More sharing options...
mrMarcus Posted November 12, 2009 Share Posted November 12, 2009 i don't know that you can get a read off of the CURL_OPT, but you can always check if the HTTP Response code(s) that are sent back by the external server(s). an HTTP response code for Timeout is 408 .. so, an example (and this is strictly an example), would be something like this: <?php if ($http_response == '408') { echo 'cURL timed out.'; } ?> of course, $http_reponse being whatever the post_back response is of the server that you are requesting information. http status codes again, just an example, but it's how i'd do it (assuming CURL_OPT_TIMEOUT doesn't have a built-in function to handle this, which i'm not sure they do .. check it out first). Quote Link to comment https://forums.phpfreaks.com/topic/181259-if-curl-takes-60-seconds-then-echo-error/#findComment-956241 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.