コアサーバーV2プランご契約でドメイン更新費用が永久無料

Cron修正程序

把任意频率的Cron修正到1分钟一次。
测试中使用监控宝15分钟一次和30分钟一次的监控都运行良好。

1<?php
2// 设定参数
3$phpfile = 'cron.php';// 需要执行的Cron文件名
4$time = 1;// 间隔分钟数
5// 关闭浏览器仍然执行
6set_time_limit(0);
7ignore_user_abort(true);
8// 读取记录
9$A=$B=$C=$D= 0;
10$F = off;
11include('cronlog.php');
12if (time() – $A < 30)
13    exit;
14// 判断是否有进程在执行
15if ($F == on)
16    exit();
17// 判断D是否为空
18if ($D == 0){
19    $D = $C;
20    $C = $B;
21    $B = $A;
22    $A = time();
23    writelog($A,$B,$C,$D,$F);
24    include($phpfile);
25    exit();
26}
27//  启动修正
28$D = $C;
29$C = $B;
30$B = $A;
31$A = time();
32$E = ($A$D)/3;
33writelog($A,$B,$C,$D,$F);
34// 计算运行次数
35$time *= 60;
36$i=round($E/$time);
37if ($i <= 0){
38    include($phpfile);
39    exit();
40}
41if ($i > 60){
42    $A=$B=$C=$D= 0;
43    $F = off;
44    writelog($A,$B,$C,$D,$F);
45    exit();
46}
47// 防止多进程运行
48$F = on;
49writelog($A,$B,$C,$D,$F);
50// 循环
51$u=1;
52while($u<=$i){
53    include($phpfile);
54    if ($A+$E-time()<120){
55        $F = off;
56        writelog($A,$B,$C,$D,$F);
57    }
58    if ($A+$E-time()<60)
59        exit();
60    sleep ($time);
61    $u++;
62}
63exit();
64// 自定义函数
65function writelog($A,$B,$C,$D,$F){
66    $file = '<?php'.PHP_EOL.'$A = '.$A.';'.PHP_EOL.'$B = '.$B.';'.PHP_EOL.'$C = '.$C.';'.PHP_EOL.'$D = '.$D.';'.PHP_EOL.'$F = '.$F.';'.PHP_EOL.'?>';
67    file_put_contents(“cronlog.php”,$file);
68}
69?>