Crontab record persisted storage (configuration file or database)It is not recommended that you use a database for CRONTAB configuration management unless you are able to 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.
Nonsense not much to say, the previous test code:
Define (' DS ', directory_separator); Requiredirname (__file__). Ds. ' Vendor '. Ds. ' autoload.php ';d ate_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 ' = [' * * * * * ', ' * * * * * ', ], ],; $c Rontab_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:08]-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 dependencies:
- Process Control Package: "Jenner/multi_process": "1.0.0",
- pcntl extension
- crontab service
Jenner/multi_ The process package is a simple processes 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 add by adding: "Jenner/crontab" to Composer.json: "1.0.0" To load this package.
The specific source code can be viewed on GitHub.
Original article, reproduced please specify: Reprint from always not enough
This article link address: PHP-based crontab scheduled task management
http://www.bkjia.com/phpjc/914778.html www.bkjia.com true http://www.bkjia.com/phpjc/914778.html techarticle PHP-based crontab timed task management by Jenner November 10, 2014 · Hits: 6 Linux crontab has always been a tool for server operations and business development. But when the timing tasks increase, ...
-