Jump to content

Recommended Posts

So im having difficulties with skipping timeout error in curl

my script calls different functions my problem is lets say if in function2 is curl timeout error it wont continue with function3 but kills entire script. Is there any way to skip function2 (if there is timeout error) and continue with function3

 

// Start calling functions

   function1();
   function2();
   function3();
   function4();
   function5();

Link to comment
https://forums.phpfreaks.com/topic/180414-curl-timeout-breaks-script/
Share on other sites

you might have used curl_close() earlier than needed. hard to tell without any more code.

Nope thats not problem simly website im calling is down and curl just cannot establish connection with it thats the case all i want to do is if website is down and curl times out the script should continue with another functions and skip this one which causes timeout.

then your logic is wrong .. you're allowing the script to end if no connection is made.

 

EDIT: really though, cURL timing out would only break your script if the code following the cURL is dependent on that call.  otherwise, the script would continue to run, just without information from the cURL.

then your logic is wrong .. you're allowing the script to end if no connection is made.

EDIT: really though, cURL timing out would only break your script if the code following the cURL is dependent on that call.  otherwise, the script would continue to run, just without information from the cURL.

Exacly. When using CURL you should check for errors before trying to extract anything from the result. i.e. return an array

<?php
$return['file'] = curl_exec($ch); 
$return['status'] = curl_getinfo($ch);
$return['error'] = curl_error($ch);
curl_close($ch);
if(!strlen($return['error'])) {
  // no error - continue
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.