The code uses PHP's package Manager composer,include to your PHP script

Source: Internet
Author: User
Tags php script

Use the database for CRONTAB configuration management unless you can ensure that the database requests remain stable for a long period of time. It is recommended that you use a NoSQL type of cache store while maintaining a persistent backup.

Test code:

Define (' DS ', directory_separator); Requiredirname (__file__). Ds. ' Vendor '. Ds. ' autoload.php '; Date_default_timezone_set (' PRC '); Error_reporting (E_all); $crontab _config= [' test_1 ' = [' name ' = ' + ' service Monitoring 1 ', ' cmd ' = ' php-v ', ' output ' = '/tmp/test.log ', ' time ' = ' * * * * * '], ' single_test ' = [' name ' = ' php-i ', ' cmd ' = ' php-i ', ' output ' = '/tmp/single_script.log ', ' time ' = = [' * * * * * ', ' * * * * * * ',],],; $crontab _server= New\jenner\zebra\crontab\crontab ($crontab _config); $crontab _server->start ();

This code uses the PHP package Manager composer, if you do not understand, you can manually put the required classes, include into your PHP script.

After running, we will view the crontab's running record in the default log file (/var/log/php_crontab.log), and of course you can specify the log file log by passing the second parameter to Crontab (make sure it is writable). The contents of the log file are as follows:

[2014-11-10 19:50:08]-content:start. pid3778 [2014-11-10 19:50:08]-content:php-v [2014-11-10 19:50:08]-content:php-i [2014-11-10 19:50:08]-content:php-i [ 2014-11-10 19:50:082881064151]-content:end. pid:3778

The log logs the program's startup time, running commands, and PID information. Since I was doing it manually, the description is not accurate for 00 seconds. When used formally, the manager can be run automatically by adding a command like the following in Crontab.

* * * * * * php php_crontab_manager.php
Manager dependent: Process Control Package: "Jenner/multi_process": "1.0.0", Pcntl extended crontab Service

The Jenner/multi_process package is a simple process control package that is primarily designed to use child processes when performing scheduled tasks, so that the parent process does not block, causing delays in scheduled tasks.

Project Address:

This project is hosted on GitHub and provides packagist package support, which you can load by adding: "Jenner/crontab": "1.0.0" in Composer.json.

Specific source code can be viewed on GitHub.

Original articles, reproduced please specify: Reprint from always enough

This article link address: PHP-based crontab scheduled task management

Code uses PHP's package Manager composer,include to your PHP script

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.