문제

I have a heavy processing script which can be started from a user via frontend in our intranet. Imagine something like this:

            $html = file_get_contents($url);
            $pattern = '/[A-Z0-9._%+-]+(@|\(at\)|\[at\])[A-Z0-9.-]+\.[A-Z]{2,4}\b/i'; //also (at) and [at]
            preg_match_all($pattern,$html,$emails);
            foreach ($emails[0] as $m)
            {
                $m[] = $m;
            }
foreach($m as $n){echo $n."<br>";}

This is just an example for illustration of the question! Don't judge it on common sense.

NOW what i want is 2 things:

  1. Stop the process on Click on a button from the user. This means: outputting the already collected array $m[].

  2. Stop the process (or better: stop the array-collecting process and jump to the echo of the already collected array) based on time (for example max. 1 minute collecting the array, THAN jumping to echoing.

I don't want to echo live and setting max execution time will stop the script without echoing.

Thanks for your wise advise on both subquestions

도움이 되었습니까?

해결책

You have to run script through ajax, and button click regsiter session by ajax

foreach ($emails[0] as $m)
            {
      if (!isset($_SESSION['STOP'])) {
                $m[] = $m;
                   } 
               else { //stop code here } 
            }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top