function cronnextrun($cron) { global $db, $tablepre, $_DCACHE, $timestamp; if (empty($cron)) { return FALSE; } list($yearnow, $monthnow, $daynow, $weekdaynow, $hournow, $minutenow) = explode('-', gmdate('Y-m-d-w-H-i', $timestamp + $_DCACHE['settings']['timeoffset'] * 3600)); if ($cron['weekday'] == -1) { if ($cron['day'] == -1) { $firstday = $daynow; $secondday = $daynow + 1; } else { $firstday = $cron['day']; $secondday = $cron['day'] + gmdate('t', $timestamp + $_DCACHE['settings']['timeoffset'] * 3600); } } else { $firstday = $daynow + ($cron['weekday'] - $weekdaynow); $secondday = $firstday + 7; } if ($firstday < $daynow) { $firstday = $secondday; } if ($firstday == $daynow) { $todaytime = crontodaynextrun($cron); if ($todaytime['hour'] == -1 && $todaytime['minute'] == -1) { $cron['day'] = $secondday; $nexttime = crontodaynextrun($cron, 0, -1); $cron['hour'] = $nexttime['hour']; $cron['minute'] = $nexttime['minute']; } else { $cron['day'] = $firstday; $cron['hour'] = $todaytime['hour']; $cron['minute'] = $todaytime['minute']; } } else { $cron['day'] = $firstday; $nexttime = crontodaynextrun($cron, 0, -1); $cron['hour'] = $nexttime['hour']; $cron['minute'] = $nexttime['minute']; } $nextrun = @gmmktime($cron['hour'], $cron['minute'], 0, $monthnow, $cron['day'], $yearnow) - $_DCACHE['settings']['timeoffset'] * 3600; $availableadd = $nextrun > $timestamp ? '' : ', available=\'0\''; $db->query("UPDATE {$tablepre}crons SET lastrun='{$timestamp}', nextrun='{$nextrun}' {$availableadd} WHERE cronid='{$cron['cronid']}'"); return TRUE; }
function cronnextrun($cron) { global $_SGLOBAL, $_SCONFIG; if (empty($cron)) { return FALSE; } list($yearnow, $monthnow, $daynow, $weekdaynow, $hournow, $minutenow) = explode('-', sgmdate('Y-m-d-w-H-i', $_SGLOBAL['timestamp'])); $cron['minute'] = explode("\t", $cron['minute']); if ($cron['weekday'] == -1) { if ($cron['day'] == -1) { $firstday = $daynow; $secondday = $daynow + 1; } else { $firstday = $cron['day']; $secondday = $cron['day'] + sgmdate('t', $_SGLOBAL['timestamp']); } } else { $firstday = $daynow + ($cron['weekday'] - $weekdaynow); $secondday = $firstday + 7; } if ($firstday < $daynow) { $firstday = $secondday; } if ($firstday == $daynow) { $todaytime = crontodaynextrun($cron); if ($todaytime['hour'] == -1 && $todaytime['minute'] == -1) { $cron['day'] = $secondday; $nexttime = crontodaynextrun($cron, 0, -1); $cron['hour'] = $nexttime['hour']; $cron['minute'] = $nexttime['minute']; } else { $cron['day'] = $firstday; $cron['hour'] = $todaytime['hour']; $cron['minute'] = $todaytime['minute']; } } else { $cron['day'] = $firstday; $nexttime = crontodaynextrun($cron, 0, -1); $cron['hour'] = $nexttime['hour']; $cron['minute'] = $nexttime['minute']; } //更新下次运行时间 $nextrun = @gmmktime($cron['hour'], $cron['minute'], 0, $monthnow, $cron['day'], $yearnow) - $_SCONFIG['timeoffset'] * 3600; $setarr = array('lastrun' => $_SGLOBAL['timestamp'], 'nextrun' => $nextrun); if ($nextrun <= $_SGLOBAL['timestamp']) { $setarr['available'] = 0; } updatetable('cron', $setarr, array('cronid' => $cron['cronid'])); return TRUE; }
function cronnextrun($cronids) { global $_SGLOBAL, $_SCONFIG; if (!is_array($cronids) || !$cronids) { return false; } $timestamp = $_SGLOBAL['timestamp']; $minutenow = gmdate('i', $timestamp + $_SCONFIG['timeoffset'] * 3600); $hournow = gmdate('H', $timestamp + $_SCONFIG['timeoffset'] * 3600); $daynow = gmdate('d', $timestamp + $_SCONFIG['timeoffset'] * 3600); $monthnow = gmdate('m', $timestamp + $_SCONFIG['timeoffset'] * 3600); $yearnow = gmdate('Y', $timestamp + $_SCONFIG['timeoffset'] * 3600); $weekdaynow = gmdate('w', $timestamp + $_SCONFIG['timeoffset'] * 3600); foreach ($cronids as $cronid) { if (!($cron = $_SGLOBAL['crons'][$cronid])) { continue; } if ($cron['weekday'] == -1) { if ($cron['day'] == -1) { $firstday = $daynow; $secondday = $daynow + 1; } else { $firstday = $cron['day']; $secondday = $cron['day'] + gmdate('t', $timestamp + $_SCONFIG['timeoffset'] * 3600); } } else { $firstday = $daynow + ($cron['weekday'] - $weekdaynow); $secondday = $firstday + 7; } if ($firstday < $daynow) { $firstday = $secondday; } if ($firstday == $daynow) { $todaytime = crontodaynextrun($cron); if ($todaytime['hour'] == -1 && $todaytime['minute'] == -1) { $cron['day'] = $secondday; $nexttime = crontodaynextrun($cron, 0, -1); $cron['hour'] = $nexttime['hour']; $cron['minute'] = $nexttime['minute']; } else { $cron['day'] = $firstday; $cron['hour'] = $todaytime['hour']; $cron['minute'] = $todaytime['minute']; } } else { $cron['day'] = $firstday; $nexttime = crontodaynextrun($cron, 0, -1); $cron['hour'] = $nexttime['hour']; $cron['minute'] = $nexttime['minute']; } $nextrun = gmmktime($cron['hour'], $cron['minute'], 0, $monthnow, $cron['day'], $yearnow) - $_SCONFIG['timeoffset'] * 3600; $_SGLOBAL['db']->query("UPDATE " . tname('crons') . " SET lastrun='{$timestamp}', nextrun='{$nextrun}' WHERE cronid='{$cronid}'"); } include_once S_ROOT . './function/cache.func.php'; updatecronscache(); updatecroncache(); }