PHP script continues after closing / stopping page

依然范特西╮ 提交于 2019-11-28 14:30:36

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 :

  • A flag variable is considered which is stored in a database table .
  • A way is provided to set the flag On or Off ( or 1 or 0 ) .
  • The flag is checked in the script and the script is stopped running if the flag is found to be 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 .

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!