Jump to content

Possible to abort a script and jump to the next block of code?


wpt394

Recommended Posts

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.