PHP-based Crontab timed task Management _php tutorial

Source: Internet
Author: User

PHP-based crontab timed task management


by Jenner November 10, 2014 · Hits: 6

Linux crontab has been the server operation and maintenance, business development of the weapon. But when scheduled tasks increase, management and migration become cumbersome and prone to problems. Here is a crontab manager written in PHP, but you still need to add a one-minute call to run the manager under Crontab. With this manager, you can achieve the following purposes:

  • Centralized management of distributed scheduled tasks
  • Multiple crontab record merges
  • 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, ...

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.