[Shell] Swoole_timer_tick and crontab for scheduled tasks and monitoring

Source: Internet
Author: User
Tags cron script

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.