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
    
    评论

报告相同问题?