The main cron script, going to be called by a PHP genorated image
simplecron.php
<?php
function func_simp_cron_major($file){
$simp_cron_job = func_simp_cron_minor($file);
if (is_array($simp_cron_job)){
foreach ($simp_cron_job as $simp_cron_run){
func_secure_include($simp_cron_run);
}
}
}
function func_secure_include($file, $once = 1){
if($once == 1){
include_once($file);
} else {
include($file);
}
}
function func_simp_cron_minor($filename){
$timenow = time();
$fp = fopen($filename, 'r');
$data = fread($fp,filesize($filename));
flock($fp,LOCK_EX);
$data = explode("\n|JOB|",$data);
$i = 0;
while($i < (count($data)-1)){
$n = $i+1;
$data[$n] = explode('|',$data[$n]);
$cron[$i]['last_run'] = $data[$n][0];
$cron[$i]['interval'] = $data[$n][1];
$cron[$i]['file'] = $data[$n][2];
$i++;
}
$i = 0;
while($i < count($cron)){
if ($timenow > ($cron[$i]['last_run']+$cron[$i]['interval'])){
$return[] = $cron[$i]['file'];
$string .= "\n|JOB|".$timenow;
$write = 1;
} else {
$string .= "\n|JOB|".$cron[$i]['last_run'];
}
$string .= '|'.$cron[$i]['interval'].'|'.$cron[$i]['file'];
$i++;
}
if ($write == 1){
flock($fp, LOCK_UN);
fclose($fp);
$fp = fopen($filename, 'w+');
flock($fp, LOCK_EX);
fwrite($fp, $string);
}
flock($fp, LOCK_UN);
fclose($fp);
return $return;
}
?> [code=php]
PHP genorated image + call simplecron....
[code=php]<?
// use <img src="cron_img.php" width="1" height="1" alt="" />
Header('Content-Type: image/gif');
include('simplecron.php');
func_simp_cron_major('cronjob.inc');
echo base64_decode('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');
?>
|JOB|1159224254|2000|a.php
|JOB|1159224254|3000|a.php
the script define what to run in cron... important... there is an \n before the first |JOB|
this should be one of the fastest PHP cron script you could find! any suggestsion?