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