dpacmittal Posted July 16, 2009 Share Posted July 16, 2009 I have made a script for my client which uploads files to some upload site. The problem is that, it sometimes works, sometimes doesn't. The problem is not with the script but with the upload site coz the same thing happens when working in browser. Sometimes upload is successful, sometimes it just stalls. So, I want to insert some code which would check, after 5 seconds of starting the upload, if the file is really being uploaded or not using CURL (I can code this). If, it has not started then try uploading again. I can code all this, but I can't run two simultaneous CURL requests. Even if I could, how do I stop the CURL request which is uploading the file and reinitiate it? To give you a more clear view: This is the algorithm: - Login into site using CURL. - Start file upload using CURL. - Simultaneously, with the above request run another CURL request which checks if the file is being uploaded or halted - if (upload is running) do nothing else try again to upload file I hope I am clear. Link to comment https://forums.phpfreaks.com/topic/166147-solved-stopping-curl-on-a-condition-and-rerunning-it/ Share on other sites More sharing options...
rhodesa Posted July 16, 2009 Share Posted July 16, 2009 You can't do that. The only thing I can think of are to set a timeout on the curl request...and if it times out, try it again. Link to comment https://forums.phpfreaks.com/topic/166147-solved-stopping-curl-on-a-condition-and-rerunning-it/#findComment-876523 Share on other sites More sharing options...
dpacmittal Posted July 16, 2009 Author Share Posted July 16, 2009 You can't do that. The only thing I can think of are to set a timeout on the curl request...and if it times out, try it again. Thankyou for response. Link to comment https://forums.phpfreaks.com/topic/166147-solved-stopping-curl-on-a-condition-and-rerunning-it/#findComment-876630 Share on other sites More sharing options...
papaface Posted July 16, 2009 Share Posted July 16, 2009 Yeah. Just add something like: curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,12); curl_setopt($ch, CURLOPT_TIMEOUT,; curl_exec($ch); if (curl_errno($ch) == false) { //no error } else { //error } Link to comment https://forums.phpfreaks.com/topic/166147-solved-stopping-curl-on-a-condition-and-rerunning-it/#findComment-876641 Share on other sites More sharing options...
dpacmittal Posted July 17, 2009 Author Share Posted July 17, 2009 Yeah. Just add something like: curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,12); curl_setopt($ch, CURLOPT_TIMEOUT,; curl_exec($ch); if (curl_errno($ch) == false) { //no error } else { //error } Since this script is used to download a file from remote server, and we don't know the file size, we can't possible use timeout as we don't know how much time it will actually take to download the file. So, I am pretty out of options. The remote server had some problems, which streams the files sometimes and doesn't stream the other times. So, I just switched to another server to solve the problem. Thanks for the responses, though. Link to comment https://forums.phpfreaks.com/topic/166147-solved-stopping-curl-on-a-condition-and-rerunning-it/#findComment-876883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.