![PHP中實(shí)現(xiàn)crontab代碼分享__第1頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-7/15/3f024223-4410-486a-b390-1624e9692969/3f024223-4410-486a-b390-1624e96929691.gif)
![PHP中實(shí)現(xiàn)crontab代碼分享__第2頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-7/15/3f024223-4410-486a-b390-1624e9692969/3f024223-4410-486a-b390-1624e96929692.gif)
![PHP中實(shí)現(xiàn)crontab代碼分享__第3頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-7/15/3f024223-4410-486a-b390-1624e9692969/3f024223-4410-486a-b390-1624e96929693.gif)
![PHP中實(shí)現(xiàn)crontab代碼分享__第4頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-7/15/3f024223-4410-486a-b390-1624e9692969/3f024223-4410-486a-b390-1624e96929694.gif)
![PHP中實(shí)現(xiàn)crontab代碼分享__第5頁(yè)](http://file2.renrendoc.com/fileroot_temp3/2021-7/15/3f024223-4410-486a-b390-1624e9692969/3f024223-4410-486a-b390-1624e96929695.gif)
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、PHP中實(shí)現(xiàn)crontab代碼分享_ 這篇文章主要介紹了PHP中實(shí)現(xiàn)crontab代碼分享,本文給出了實(shí)現(xiàn)代碼和用法方法,需要的伴侶可以參考下 1. 預(yù)備一個(gè)標(biāo)準(zhǔn)crontab文件 ./crontab 代碼如下: # m h dom mon dow command * * * * * date /tmp/cron.date.run 2. crontab -e 將此cron.php腳本加入系統(tǒng)cron 代碼如下: * * * * * /usr/bin/php cron.php 3. cron.php 源碼 代碼如下: / 從./crontab讀取cron項(xiàng),也可以從其他長(zhǎng)久存儲(chǔ)(mysql、re
2、dis)讀取 $crontab = file(./crontab); $now = $_SERVERREQUEST_TIME; foreach ( $crontab as $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 )
3、 continue; $pid = pcntl_fork(); if ($pid = -1) die(could not fork); else if ($pid) / we are the parent pcntl_wait($status, WNOHANG); /Protect against Zombie children else / we are the child $cmd; exit; /* */ class Crontab /* * Finds next execution time(stamp) parsin crontab syntax, * after given sta
4、rting timestamp (or current time if ommited) * * param string $_cron_string: * * 0 1 2 3 4 * * * * * * * - - - - - * | | | | | * | | | | +- day of week (0 - 6) (Sunday=0) * | | | +- month (1 - 12) * | | +- day of month (1 - 31) * | +- hour (0 - 23) * +- min (0 - 59) * param int $_after_timestamp tim
5、estamp default=current timestamp * return int unix timestamp - next execution time will be greater * than given timestamp (defaults to the current timestamp) * throws InvalidArgumentException */ public static function parse($_cron_string,$_after_timestamp=null) if(!preg_match(/(*(/0-9+)?)|0-9-,/+)s+
6、(*(/0-9+)?)|0-9-,/+)s+(*(/0-9+)?)|0-9-,/+)s+(*(/0-9+)?)|0-9-,/+)s+(*(/0-9+)?)|0-9-,/+)$/i,trim($_cron_string) throw new InvalidArgumentException(Invalid cron string: .$_cron_string); if($_after_timestamp !is_numeric($_after_timestamp) throw new InvalidArgumentException($_after_timestamp must be a va
7、lid unix timestamp ($_after_timestamp given); $cron = preg_split(/s+/i,trim($_cron_string); $start = empty($_after_timestamp)?time():$_after_timestamp; $date = array( minutes =self:_parseCronNumbers($cron0,0,59), hours =self:_parseCronNumbers($cron1,0,23), dom =self:_parseCronNumbers($cron2,1,31), m
8、onth =self:_parseCronNumbers($cron3,1,12), dow =self:_parseCronNumbers($cron4,0,6), ); / limited to time()+366 - no need to check more than 1year ahead for($i=0;$i=60*60*24*366;$i+=60) if( in_array(intval(date(j,$start+$i),$datedom) in_array(intval(date(n,$start+$i),$datemonth) in_array(intval(date(
9、w,$start+$i),$datedow) in_array(intval(date(G,$start+$i),$datehours) in_array(intval(date(i,$start+$i),$dateminutes) ) return $start+$i; return null; /* * get a single cron style notation and parse it into numeric value * * param string $s cron string element * param int $min minimum possible value
10、* param int $max maximum possible value * return int parsed number */ protected static function _parseCronNumbers($s,$min,$max) $result = array(); $v = explode(,$s); foreach($v as $vv) $vvv = explode(/,$vv); $step = empty($vvv1)?1:$vvv1; $vvvv = explode(-,$vvv0); $_min = count($vvvv)=2?$vvvv0:($vvv0=*?$min:$vvv0
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年全球及中國(guó)飼料中間體化學(xué)品行業(yè)頭部企業(yè)市場(chǎng)占有率及排名調(diào)研報(bào)告
- 2025-2030全球高速標(biāo)簽打印機(jī)行業(yè)調(diào)研及趨勢(shì)分析報(bào)告
- 2025年全球及中國(guó)汽車座椅加熱通風(fēng)線束行業(yè)頭部企業(yè)市場(chǎng)占有率及排名調(diào)研報(bào)告
- 2025-2030全球條形碼庫(kù)存管理系統(tǒng)行業(yè)調(diào)研及趨勢(shì)分析報(bào)告
- 2025-2030全球生物基電池行業(yè)調(diào)研及趨勢(shì)分析報(bào)告
- 2025年全球及中國(guó)農(nóng)場(chǎng)畜牧管理軟件行業(yè)頭部企業(yè)市場(chǎng)占有率及排名調(diào)研報(bào)告
- 2025-2030全球印刷級(jí)熱敏紙行業(yè)調(diào)研及趨勢(shì)分析報(bào)告
- 擔(dān)保函保證合同
- 2025監(jiān)控售后維修合同
- 房屋買賣合同范文
- 河南2025年河南職業(yè)技術(shù)學(xué)院招聘30人筆試歷年參考題庫(kù)附帶答案詳解
- 成人氧氣吸入療法-中華護(hù)理學(xué)會(huì)團(tuán)體標(biāo)準(zhǔn)
- 北方春節(jié)的十大風(fēng)俗
- 婚介公司紅娘管理制度
- 煤礦電氣試驗(yàn)規(guī)程
- JCT796-2013 回彈儀評(píng)定燒結(jié)普通磚強(qiáng)度等級(jí)的方法
- 物業(yè)客服培訓(xùn)課件PPT模板
- 員工工資條模板
- 火力發(fā)電廠節(jié)能管理制度實(shí)施細(xì)則
- 華為攜手深圳國(guó)際會(huì)展中心創(chuàng)建世界一流展館
- 2023版思想道德與法治專題2 領(lǐng)悟人生真諦 把握人生方向 第3講 創(chuàng)造有意義的人生
評(píng)論
0/150
提交評(píng)論