Jump to content

perform function on timeout


Darkstar

Recommended Posts

I basically have a script that fetches info from another site using curl.  To avoid multiple instances of the fetch at one time I have it create a file as soon as it begins to fetch and set a curl timeout for the fetch.  The problem I'm having is if it times out it doesn't remove the file, it just times out and doesn't continue.  I looked up possibilities and found set_time_limit(0); but i don't want it to be able to run forever, I just want it to write the file, attempt to fetch and if it hasn't completed after x seconds, remove the file.

 

any thoughts?

Link to comment
Share on other sites

        $timeout = 5; // set to zero for no timeout

        //retrieve file
        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, 'http://www.xxxxxx.com/xxxxx.aspx');
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
        $file = curl_exec($ch);

 

this is what i'm using right now. 

Link to comment
Share on other sites

The only other thing I can think of is the possibility that because this particular page is called by ajax that if the user navigates away before it finishes loading/running it may stop the script, but i'm not sure if that's even possible.  Would the script continue running or would it stop?  There's more to the actual script, that part fetches it, then it's parsed as XML and put into a variable.  The variable is then saved as XML locally as a cache and the variable is then used as output.

 

If the script is stopping due to a user navigating away, is there a way to make it run completely through?

Link to comment
Share on other sites

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.