wpt394 Posted July 22, 2007 Share Posted July 22, 2007 Greetings. I'm running a block of code that takes a little bit of time to run....However, it is not absolutely necessary that the code runs completely. I was wondering if it is possible to create a button/link that would let a user stop the execution of that piece of code and then resume execution starting with the next 'block' of code. Please don't suggest to me that if the code isn't necessary I shouldn't have it in the webpage, as that is not the solution I'm looking for. Thanks for the help. Quote Link to comment Share on other sites More sharing options...
dbo Posted July 22, 2007 Share Posted July 22, 2007 Don't think that the button approach will work, unless MAYBE if you like had it called in an iframe or something and you could reload the iframe... I dunno. You might be able to write some additional logic i the script that you handle by passing in some extra command line arguments or something. This would basically just tell you when it's ok to stop depending on what situations. Yeah I know it's not the answer you want but it's a good practice to take a step back from things and ask yourself the ultimate goal you're trying to accomplish and if it can be accomplished another way. Often times we get on a one track mind and get hung up when there is a more obvious (and better) solution right in front of us. Good luck! Quote Link to comment Share on other sites More sharing options...
dbo Posted July 22, 2007 Share Posted July 22, 2007 Hrmm, on another note you might be able to just tell the external script to run in the background or something if you're using exec or system calls. Depends on what it's doing and .... stuff. Quote Link to comment Share on other sites More sharing options...
wpt394 Posted July 22, 2007 Author Share Posted July 22, 2007 Thanks for the reply.... I'm using a multi_curl... Basically I'm looking up information on multiple pages for a user. However, the request usually takes about 30 seconds, and I thought it would be nice if the user could stop the curl request and just view what had been retrieved thus far...For example...here is the code I'd like to work with... //Set all of the multi curlopts, urls, etc. //Run the curl_multi do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); while ($active and $mrc == CURLM_OK) { if (curl_multi_select($mh) != -1) { do { $mrc = curl_multi_exec($mh, $active); } while ($mrc == CURLM_CALL_MULTI_PERFORM); } } if ($mrc != CURLM_OK) { print "Curl multi read error $mrc\n"; } //When user clicks button, jump to HERE where the results begin to be parsed out foreach ($urls as $i => $url) { $res[$i]=curl_multi_getcontent($conn[$i]); curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); } (Sorry I know the execution loops are messy, but with more simplistic execution code, curl_multi really seems to eat up my cpu clock. Quote Link to comment Share on other sites More sharing options...
dbo Posted July 22, 2007 Share Posted July 22, 2007 Hrmm. I don't know anything about multi_curl but what I'm wondering is if you could wrapper that code in an external script... call it with system or exec (running it in the background... )and have the script output to some sort of datafile or db table. Then you could have an ajax call that constantly pings the datafile and only updates your page with the new information... all the while keeping your page responsive. 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.