From 34c001b00ccbf8722ba4328f5eaa5ece00cba3c4 Mon Sep 17 00:00:00 2001 From: zhujinyong Date: Fri, 11 Jan 2013 06:25:36 +0000 Subject: [PATCH] * code for task#1025. --- bin/crontab/config.php | 4 ++++ bin/crontab/crontab.php | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 bin/crontab/config.php create mode 100755 bin/crontab/crontab.php diff --git a/bin/crontab/config.php b/bin/crontab/config.php new file mode 100644 index 0000000000..7343b2eeb3 --- /dev/null +++ b/bin/crontab/config.php @@ -0,0 +1,4 @@ +backup = array('schema' => '* * * * *', 'script' => '../php/backup.php'); +$crontab->computeburn = array('schema' => '1 23 * * *', 'script' => '../php/computeburn.php'); diff --git a/bin/crontab/crontab.php b/bin/crontab/crontab.php new file mode 100755 index 0000000000..b50767e200 --- /dev/null +++ b/bin/crontab/crontab.php @@ -0,0 +1,37 @@ + $cron) +{ + $tasks[$key]->cron = CronExpression::factory($cron['schema']); + $tasks[$key]->time = $tasks[$key]->cron->getNextRunDate()->format('Y-m-d H:i'); +} + +/* run as daemon. */ +while(1) +{ + foreach($crontab as $key => $cron) + { + if($tasks[$key]->cron->getNextRunDate()->format('Y-m-d H:i') != $tasks[$key]->time) + { + $time = date('Y-m-d H:i:s'); + $output = system('php ' . $cron['script'], $retval); + $content = $time . ' ' . $key . ' return ' . $retval . ' : ' . $output . "\n"; + logCron($content); + $tasks[$key]->time = $tasks[$key]->cron->getNextRunDate()->format('Y-m-d H:i'); + } + } + sleep(60); +} + +/* log cron results. */ +function logCron($content) +{ + $file = dirname(dirname(dirname(__FILE__))) . '/tmp/cron.log'; + $fp = fopen($file, "a"); + fwrite($fp, $content); + fclose ($fp); +}