Darkstar Posted December 7, 2007 Share Posted December 7, 2007 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? Quote Link to comment Share on other sites More sharing options...
daq Posted December 7, 2007 Share Posted December 7, 2007 Will using curl arguments work? --connect-timeout <seconds> Maximum time allowed for connection -m/--max-time <seconds> Maximum time allowed for the transfer Quote Link to comment Share on other sites More sharing options...
Darkstar Posted December 7, 2007 Author Share Posted December 7, 2007 $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. Quote Link to comment Share on other sites More sharing options...
daq Posted December 7, 2007 Share Posted December 7, 2007 It works correctly for me. When timeout is less than time it takes to transfer, it quits. Could it be that something else in your function hangs the program? Quote Link to comment Share on other sites More sharing options...
Darkstar Posted December 8, 2007 Author Share Posted December 8, 2007 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? Quote Link to comment 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.