Php间隔在某个时间后停止

时间:2017-10-30 05:57:36

标签: php server intervals

我的php服务器有问题。 我发现,我的php间隔由于某种原因而停止。 这是代码。

main.php



<?php
ignore_user_abort();
set_time_limit(0);
$interval=1;
$j=1;
upload_content("<\nStart: ".date("Y-m-d H:i:s",strtotime("+8 hours"))."\r\n");
do{
    $run = include 'config.php';
    if(!$run) {
        upload_content("\n"."Cycle: ".$j."\t|End Onservice update \t|".date("Y-m-d H:i:s",strtotime("+8 hours"))."\r");
        die('no no');
    }
    if(date("s") == "30"||date("s") == "00"){
        require_once $_SERVER['DOCUMENT_ROOT'].'/php/service/test.php';
        
        if($update_success == TRUE){
            $content = "\n"."Cycle: ".$j."\t|Update Success  \t|".date("Y-m-d H:i:s",strtotime("+8 hours"))."\r";
            upload_content($content);
            $j+=1;
        } else {
            $content = "\n"."Cycle: ".$j."\t|Update Fail!! \t|".date("Y-m-d H:i:s",strtotime("+8 hours"))."\r";
            upload_content($content);
            $j+=1;
        }
        $interval = 28;
    }
    upload_content("Interval: ".$interval."\n");
    if(sleep($interval)){
        upload_content("End Interval\n");
    }
    $interval = 1;
}while(true);


function upload_content($content){
    $file = $_SERVER['DOCUMENT_ROOT'].'/record/record_Onservice.txt';
    $fp = @fopen($file, "a+");
    fwrite($fp,$content);
    fclose($fp);
}

?>
&#13;
&#13;
&#13; 该代码用于每半分钟更新一次信息。在实际功能中,可能只有几秒钟更新,但这次我只是使用test.php进行测试。为了确保没有累积延迟,我会在分钟内继续检查第二个。

的config.php

&#13;
&#13;
<?php
return 1;
?>
&#13;
&#13;
&#13;

test.php的

&#13;
&#13;
<?php
$update_success = TRUE;
?>
&#13;
&#13;
&#13;

record_Onservice.txt(Result)

&#13;
&#13;
Cycle: 1	|Update Success  	|2017-10-30 13:35:00
Interval: 28
Interval: 1
Interval: 1

Cycle: 2	|Update Success  	|2017-10-30 13:35:30
Interval: 28
Interval: 1
Interval: 1

Cycle: 3	|Update Success  	|2017-10-30 13:36:00
Interval: 28
Interval: 1
Interval: 1

Cycle: 4	|Update Success  	|2017-10-30 13:36:30
Interval: 28
End Interval
Interval: 1
Interval: 1
Interval: 1
Interval: 1
Interval: 1
Interval: 1
&#13;
&#13;
&#13;

0 个答案:

没有答案