本文整理匯總了PHP中Cron::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP Cron::save方法的具體用法?PHP Cron::save怎麽用?PHP Cron::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cron
的用法示例。
在下文中一共展示了Cron::save方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: poorMansCron
static function poorMansCron()
{
$intervals = array("minute", "five", "fifteen", "hour", "week");
foreach ($intervals as $interval) {
$entity = getEntity(array("type" => "Cron", "metadata_name" => "interval", "metadata_value" => $interval));
if (!$entity) {
$entity = new Cron();
$entity->interval = $interval;
$entity->save();
}
Cron::run($interval, false);
}
return;
}
示例2: run
static function run($interval, $ignore_last_run = true)
{
$phpbin = PHP_BINDIR . "/php";
if ($ignore_last_run) {
shell_exec('echo $phpbin -q ' . SITEPATH . 'cron/' . $interval . '.php | at now');
return;
}
$entity = getEntity(array("type" => "Cron", "metadata_name" => "interval", "metadata_value" => $interval));
if (!$entity) {
$entity = new Cron();
$entity->interval = $interval;
$entity->save();
}
$last_ran = $entity->last_ran;
if (!$last_ran) {
$last_ran = 0;
}
switch ($interval) {
case "minute":
$seconds = 60;
break;
case "five":
$seconds = 60 * 5;
break;
case "fifteen":
$seconds = 60 * 15;
break;
case "hour":
$seconds = 60 * 60;
break;
case "week":
default:
$seconds = 60 * 60 * 24 * 7;
break;
}
$time = time();
if ($time > $last_ran + $seconds) {
$shell = $phpbin . ' -q ' . SITEPATH . 'cron/' . $interval . '.php > /dev/null 2>/dev/null &';
shell_exec($shell);
$last_ran = $time;
$entity = getEntity(array("type" => "Cron", "metadata_name" => "interval", "metadata_value" => $interval));
if ($entity) {
$entity->last_ran = $last_ran;
$entity->save();
}
}
return;
}