douxuanpa8298 2013-10-02 21:58
浏览 32
已采纳

关闭/停止页面后PHP脚本继续

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.

  • 写回答

2条回答 默认 最新

  • dpchen2004 2013-10-02 22:15
    关注

    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 .

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog