There are three main steps to completing tasks and monitoring manually:
1. mission_cron.php (timed automatic task script):
<? PHP /* * * Automatic task timer (5s execution). * Swoole_timer_tick resolution of second-level timing; * To adjust, note the configuration path and mission_cron_monitor. * * Daemon Run: * ./miss Ion_cron_monitor * * Foreground Run: * php mission_cron.php * * Stop: * */Swoole_timer_tick ( c7>function() { // Query result //transactional update //logging Log// output result }
2. Mission_cron_monitor (run by crontab, monitor the above script):
#/bin/bash# Monitor the timer and disconnect the reboot. # # crontab usedinch/var/spoor/cron/# (Crontab-e) # # @farwish. Comphpbin=/usr/local/php7/bin/Phpcurdir=`dirname$0' Script=${curdir}/mission_cron.phpprocess=`PSAux |grep-Vgrep|grep${script} 'ifTest-z"$process"; Thennohup ${phpbin} ${script}>/dev/NULL 2>&1&fi
Here CurDir does not use ' pwd ', because PWD obtains the current working directory, the directory of non-executable script, a bit different.
The role of nohup is not affected by the terminal hangs, with the & background operation, the perfect realization of daemon.
3. Set up a user-level cron script.
# User-level Run cron.# weekly command # @farwish. com# per minute */ 1 * * * */home/www/project/mission_cron_monitor
Complete the above three steps, the main work is finished, you can run to see the effect;
Reiterate: The mission_cron.php task does not have to be wrapped within the Swoole_timer_tick callback function, only in seconds/milliseconds.
Although the script is simple, there are some issues to be careful about:
1. Troubleshooting: The task is not executed by looking at the log/var/log/cron whether there is an execution record,
There are scripting issues, syntax errors, or other things to do. Note that absolute paths are used in scripts.
2. Level: System-level task/ect/crontab
User-level tasks are edited directly with CRONTAB-E (storage location/var/spoor/cron/weichen)
Program-level task Swoole_timer_tick (+, function () {});
3. Option: CRONTAB-E
CRONTAB-L # Current User-owned Cron
Crontab-r # Delete The current user's Cron
Crontab-ri # Ask before deleting
More Crontab-h
Link:http://www.cnblogs.com/farwish/p/6230728.html
[Shell] Swoole_timer_tick and crontab combination for scheduled tasks and monitoring