There's a PHP function which lets you delay script execution till a point in time.
So let's say I have cron.php
:
<?php
// Usage:
// cron.php [interval|schedule] [script] [interval|stamp]
if(!isset($argc) || count($argc)!=2)die; // security precaution
$time=(int)$argv[3]; // just in case :)
if($argv[1]=='schedule'){
time_sleep_until((int)$_GET['until']);
include_once($time);
}elseif($argv[1]=='interval')
while(true){ // this is actually an infinite loop (you didn't ask for an "until" date? can be arranged tho)
usleep($time*1000); // earlier I said milliseconds: 1000msec is 1s, but this func is for microseconds: 1s = 1000000us
include_once($argv[2]);
}
?>
And your classes
/functions
file:
// Const form K2F - Are we on windows?
define('ISWIN', strpos(strtolower(php_uname()),'win')!==false &&
strpos(strtolower(php_uname()),'darwin')===false );
// Function from K2F - runs a shell command without waiting (works on all OSes)
function run($cmd){
ISWIN ? pclose(popen('start /B '.$cmd,'r')) : exec($cmd.' > /dev/null &');
}
script_schedule($script,$time){
if(is_string($time))$time=strtotime($time);
run('php -f -- schedule '.escapeshellarg($script).' '.$time);
}
script_interval($script,$mseconds){
run('php -f -- interval '.escapeshellarg($script).' '.$mseconds);
}
It ought to work. By the way, K2F is this framework that makes your dreams come true..faster. ;). Cheers.
Edit: If you still want the parts about counting running jobs and/or deleting(stopping) them, I can help you out with it as well. Just reply to my post and we'll follow up.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…