Reputation: 57
Seems php scripts continue even after closing or stopping a page.
for example, if my script is run by /localhost/test.php
after I close the page, sometimes it continues to run. I'm pretty sure restarting apache clears it out but is there a better way to terminate the php script after it's started.
Upvotes: 1
Views: 4526
Reputation: 2492
You could use ignore_user_abort but I think it only applies if you are running PHP as a command line script .
When running scripts from browser , in my experience I have realized scripts running even after the browser was closed . I did not go further to check how long they used to run .
The scripts that does huge processing that could run many minutes , I used to have control as below :
On
or Off
( or 1
or 0
) .Off
( or 0
) .One way to consider the flag is in a loop as below :
while(true)
{
/* Your code here which probably does lot of processing */
if($flag === false) break; // Or exit if you prefer
}
If you have code that need to run following the loop , you would use break .
If you want to abruptly stop the script you could use exit instead in its place .
Upvotes: 2
Reputation: 2657
check this out: http://php.net/manual/en/function.ignore-user-abort.php
Sets whether a client disconnect should cause a script to be aborted.
Upvotes: 2