duanmao1975 2012-06-21 21:54
浏览 78

运行一个无限循环的PHP文件

I am trying to run this php script in my linux based server.

$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 

and it workes fine if I run it from a simple browser (ofcourse it stops working when I close it).

I am trying to run it through a perl script

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

and run the perl script like so

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

but it doesn't work when I am trying to run it from the server.

  • 写回答

1条回答 默认 最新

  • dongliyi967823 2012-06-21 22:10
    关注

    By looking at the code your probably better to setup a CRON job. If your server doesn't support CRON then you could try adding...

    set_time_limit(0);
    

    or try adding -q to the php command like so:

    php -q /home/user/example.php
    
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计