如何创建不可停止的while循环,如果它已经在运行不要再次运行它,我假设如果脚本运行它将更新数据库中的最后一个cron时间,并且脚本将检查当前时间 - 40秒是否小于最后一个cron时间。我所拥有的样本,但那是过度循环(一次又一次地运行做过程)谢谢!
<?php
ignore_user_abort(1); // run script in background
set_time_limit(0); // set limit to 0
function processing()
{
//some function here
setting::write('cron_last_time', $time); // write cron last time to database
}
$time = current_timestamp(); // current time
$time_before = $time - 20; //
$settings = setting::read('module_cron_email'); // Get last cron time from database ( in array )
$time_last = $settings['setting_value']; // Last cron time get value from array
if ($time_before < $time_last) // check if time before is less than last cron time
{
do{
processing(); //run our function
sleep(7); // pause for 7 seconds
continue; // continue
}
while(true); // loop
}else{
echo "already running";
die();
}
?>