Since the crontab of the server can only be accurate to minutes, the starting point of the program is also minutes. Configuration File: the configuration file is used to return the scheduled task file to be executed. Pay attention to the usage of *. There are two modes, is Y-m-dH: I: year month day hour NH: I: Week (1
Since the crontab of the server can only be accurate to minutes, the starting point of the program is also minutes. Configuration File: the configuration file is used to return the scheduled task file to be executed. Pay attention to the usage of *. There are two modes, y-m-d H: I: Mm-mm: I: Mm-dd (1-7 | Monday-Sunday ).
Since the crontab of the server can only be accurate to minutes, the starting point of the program is also minutes.
Total includes but partially:
1. configuration file:
The configuration file is used to return the scheduled task file to be executed. Pay attention to the usage of *. There are two modes:
Y-m-d H: I: Mm-dd hour n h: I: Week (1-7 | Monday-Sunday) hour
Configuration File: croning. php
/*** Task Manager Configuration File ** Y-m-d H: I: mm/DD * n h: I: Week (1-7 | Monday-Sunday) hour **: fixed time, only one time **-12-25: hour of a month/day of each year *: 49: execute **-* 20:00: Execute at 08:00 every night **-*-**: *: Execute at every minute ** 2: run *** at every Tuesday to indicate any time at the current position. And so on .... ** format: * array (* key => value, *); ** Note: * key indicates the execution time defined. value indicates the file to be executed, which can be an array or a string, when multiple tasks are executed at the same time, use the one-dimensional array mode to avoid overwriting keys. **/Return array ('2017-12-25 '=> '2017. php', '2017-12-* '=> '2017. php ', '1' => '6546. php ',' *-12-25 '=> array ('2017. php', '2017. php '));
Ii. Main PHP files executed by the cronjob Server:
It mainly processes and analyzes which files can be executed at that time. And write the execution record file.
$ __Value) {if (strpos ($ __key, '-') = false) {// weekly processing of preg_match ('@ ^ ([\ d \ *] +) ([\ d \ *] +) :( [\ d \ *] +) $ @ U', $ __key, $ match);} else {// normal processing of preg_match ('@ ^ ([\ d \ *] +) \-([\ d \ *] +) \-([\ d \ *] +) ([\ d \ *] +) :( [\ d \ *] +) $ @ U', $ __key, $ match);} if ($ match) {array_shift ($ match); if (_ getPreg ($ match, $ __now )) {// is the file to be executed $ __onfile = array_merge ($ __onfile, is_array ($ __value )? $ __Value: array ($ __value) ;}}}if ($ __onfile) {__ onFile = array_unique ($ __onfile ); foreach ($ __onfile as $ __value) {if (file_exists (ONING_ROOT. '/'. $ __value) {$__time_star2 = microtime (true); Common: fileLog (DATA_ROOT. '/log/cron_index.log', $ __value. 'execution started ----------'. date ('Y-m-d H: I: s '). '-----------', $ __echo); include ONING_ROOT. '/'. $ __value; Common: fileLog (DATA_ROOT. '/ Log/cron_index.log ', $ __value. 'execution ended (time spent :'. (microtime (true)-$__time_star2) * 1000 ). 'Ms) ------------- ', $ __echo) ;}} Common: fileLog (DATA_ROOT. '/log/cron_index.log', 'execution cron ends (total execution time :'. (microtime (true)-$ __time_star) * 1000 ). 'Ms )*************'. date ('Y-m-d H: I: s '). '*****************'. "\ n", $ __echo);/*** process the regular result and return whether the file was to be executed * @ param array $ match the regular result, array * @ param integer $ _ Now timestamp * @ return bool */function _ getPreg ($ match, $ __now) {$ back = false; list ($ __y, $ __m, $ __d, $ __n, $ __h, $ __ I) = explode ('-', date ('Y-m-d-N-H-I ', $ __now); $ argc = count ($ match); if ($ argc = 3) {$ argc = $ match [0] = '*'? $ __N: $ match [0]; $ argc. = ''; $ argc. = $ match [1] = '*'? $ __H: $ match [1]; $ argc. = ':'; $ argc. = $ match [2] = '*'? $ __ I: $ match [2]; $ back = date ('n H: I ', $ __now) == date ($ argc, $ __now )? True: false;} elseif ($ argc = 5) {$ argc = $ match [0] = '*'? $ __Y: $ match [0]; $ argc. = '-'; $ argc. = $ match [1] = '*'? $ __M: $ match [1]; $ argc. = '-'; $ argc. = $ match [2] = '*'? $ __D: $ match [2]; $ argc. = ''; $ argc. = $ match [3] = '*'? $ __H: $ match [3]; $ argc. = ':'; $ argc. = $ match [4] === '*'? $ __ I: $ match [4]; $ back = date ('Y-m-d H: I ', $ __now) === date ($ argc, $ __now )? True: false;} return $ back ;}
3. Many scheduled files to be executed:
This is the real code to be executed: including collection, data sorting and analysis..., the file path is written to the value of the configuration file. For Files executed at the same time, remember the one-dimensional array mode.
Source: http://www.pangyiguang.com/a_76