我的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;
的config.php
<?php
return 1;
?>
&#13;
test.php的
<?php
$update_success = TRUE;
?>
&#13;
record_Onservice.txt(Result)
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;