php 调度,调度php脚本

有一个PHP函数,可以让你将脚本执行延迟到某个时间点.

所以我想说我有cron.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]);

}

?>

你的类/函数文件:

// 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);

}

它应该工作.顺便说一下,K2F就是这个让你的梦想成真的框架. ).干杯.

编辑:如果您仍然需要有关计算正在运行的作业和/或删除(停止)它们的部分,我也可以帮助您解决它.只需回复我的帖子,我们就会跟进.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值