【问题标题】:run a php file with an endless loop运行一个无限循环的 php 文件
【发布时间】:2012-06-24 05:31:07
【问题描述】:

我正在尝试在我的基于 linux 的服务器上运行这个 php 脚本。

$today      = strtotime("today");
$tommorow   = date("Y-m-d", strtotime("+1day",$today));
$today      = date("Y-m-d");

//Endless loop because the data here updates around the clock 
while(1){

    while (time() <= strtotime("$tommorw 8:00PM")){

            sleep(30);
            flush();
        }

    }//end 24 h loop
    //save the file as a date file and delete it's content


    //move on to the next day   
    $today      = strtotime("today");
    $tommorow   = date("Y-m-d", strtotime("+1day",$today)); 

}//end of endless loop 

如果我从一个简单的浏览器运行它就可以正常工作(当然当我关闭它时它会停止工作)。

我正在尝试通过 perl 脚本运行它

chdir("mydir");
exec('indices.php');  #tryed also system("php indices.php");

然后像这样运行 perl 脚本

./PROMadadim.pl >> ./PROMadadim.log &

但是当我尝试从服务器运行它时它不起作用。

【问题讨论】:

  • 它被称为守护进程,google "php Daemon"
  • 为什么说“它不起作用”?具体会发生什么?它是否正在运行但功能不正确?它根本不运行吗(ps -A 什么也没有显示)?
  • 设置一个 cron 作业。几乎不建议使用无限循环。

标签: php linux perl


【解决方案1】:

通过查看代码,您可能会更好地设置 CRON 作业。如果您的服务器不支持 CRON,那么您可以尝试添加...

set_time_limit(0);

或尝试将 -q 添加到 php 命令中,如下所示:

php -q /home/user/example.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    相关资源
    最近更新 更多