如果您无法下载资料,请参考说明:
1、部分资料下载需要金币,请确保您的账户上有足够的金币
2、已购买过的文档,再次下载不重复扣费
3、资料包下载后请先用软件解压,在使用对应软件打开
PHP中如何实现crontab代码PHP中如何实现crontab代码PHP是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,利于学习,使用广泛,主要适用于Web开发领域。下面,小编为大家搜索整理了PHP中如何实现crontab代码,希望能给大家带来帮助!更多精彩内容请及时关注我们应届毕业生考试网!1.准备一个标准crontab文件./crontab代码如下:#mhdommondowcommand*****date>/tmp/cron.date.run2.crontab-e将此cron.php脚本加入系统cron代码如下:*****/usr/bin/phpcron.php3.cron.php源码代码如下://从./crontab读取cron项,也可以从其他持久存储(mysql、redis)读取$crontab=file('./crontab');$now=$_SERVER['REQUEST_TIME'];foreach($crontabas$cron){$slices=preg_split("/[s]+/",$cron,6);if(count($slices)!==6)continue;$cmd=array_pop($slices);$cron_time=implode('',$slices);$next_time=Crontab::parse($cron_time,$now);if($next_time!==$now)continue;$pid=pcntl_fork();if($pid==-1){die('couldnotfork');}elseif($pid){//wearetheparentpcntl_wait($status,WNOHANG);//ProtectagainstZombiechildren}else{//wearethechild`$cmd`;exit;}}/*https://github.com/jkonieczny/PHP-Crontab*/classCrontab{/***Findsnextexecutiontime(stamp)parsincrontabsyntax,*aftergivenstartingtimestamp(orcurrenttimeifommited)**@paramstring$_cron_string:**01234*******-----*|||||*||||+-----dayofweek(0-6)(Sunday=0)*|||+-------month(1-12)*||+---------dayofmonth(1-31)*|+-----------hour(0-23)*+-------------min(0-59)*@paramint$_after_timestamptimestamp[default=currenttimestamp]*@returnintunixtimestamp-nextexecutiontimewillbegreater*thangiventimestamp(defaultstothecurrenttimestamp)*@throwsInvalidArgumentException*/publicstaticfunctionparse($_cron_string,$_after_timestamp=null){if(!preg_match('/^((*(/[0-9]+)?)|[0-9-,/]+)s+((*(/[0-9]+)?)|[0-9-,/]+)s+((*(/[0-9]+)?)|[0-9-,/]+)s+((*(/[0-9]+)?)|[0-9-,/]+)s+((*(/[0-9]+)?)|[0-9-,/]+)$/i',trim($_cron_string))){thrownewInvalidArgumentException("Invalidcronstring:".$_cron_string);}if($_after_timestamp&&!is_numeric($_after_timestamp)){thrownewInvalidArgumentException("$_after_timestampmustbeavalidunixtimestamp($_after_timestampgiven)");}$cron=preg_split("/[s]+/i",trim($_cron_string));$start=empty($_after_timesta
An****70
实名认证
内容提供者
最近下载