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: * ./mission_cron_monitor * * Foreground run: * php mission_cron.php * * Stop: * kill-9 PID * * @farwish. com */swoole_timer_tick (), function () { //Query results //Transactional update //log logs// output results}
2. Mission_cron_monitor (run by crontab, monitor the above script):
#/bin/bash# Monitor the timer and disconnect the reboot. # # crontab used in/var/spoor/cron/# (CRONTAB-E) # # @farwish. comphpbin=/usr/local/php7/bin/ Phpcurdir= ' dirname $ ' script=${curdir}/mission_cron.phpprocess= ' PS aux | Grep-v grep | grep ${script} ' if Test-z ' $process "; Then nohup ${phpbin} ${script} >/dev/null 2>&1 &fi
Here CurDir does not use ' pwd ' because the PWD gets the current working directory, the directory where the script is not executed, and you can get a detailed explanation through man.
Pwd-print Name of current/working directory
Dirname-strip last component from file name
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# executes */1 per minute * * * */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
[Shell] Swoole_timer_tick and crontab for scheduled tasks and monitoring