Crontabphp automatic running method introduction

Source: Internet
Author: User
Crontabphp automatic running method introduction
This article introduces how to use crontab in php to automatically run related programs. if you need it, refer to it.

Crontab-operate the Daemon of each user and the execution schedule. The specific parameters are described as follows:

Crontab file [-u user]-replace the current crontab with the specified file. Crontab-[-u user]-replace the current crontab with the standard input. crontab-1 [user]-list the current crontab of the user. crontab-e [user]-edit the current crontab of the user. crontab-d [user]-delete the current crontab of the user. crontab-c dir-specifies the crontab directory. Crontab file format: m h d m d cmd.

M: minute (0-59 ). H: Hour (0-23 ). D: Day (1-31 ). M: month (1-12 ). D: days in a week (0 ~ 6, 0 is Sunday ). The program to be run by cmd is sent to sh for execution. the shell contains only three environment variables: USER, HOME, and SHELL.

The following are some specific application examples for your reference.

Sample code: # min hour day month dayofweek command #106 * date at every DAY #0 */2 * date every two hours # every two hours from PM to AM, AM,-7/2, 8 * ** date #4 of each month and 11: 0 11 a.m. from Monday to wed date of every week # a.m. of February 4: 0 4 1 jan * date example lark: ~> The crontab-1 lists the user's current crontab. # min hour day month dayofweek command 10 6 * date 0 */2 * date 0 23-7/2, 8 * date

In linux, you must pay special attention to the environment variables when using crontab. here, we take the execution of oracle sqlplus as an example to describe how to use crontab. 1. crontab usage: crontab [-e |-l |-r] file name-e: edit task-l: Display task information-r: delete scheduled execution task information 2, files processed in crontab are in the format of minutes, hours, days, months, and weeks. * indicates that all conditions are 5 * rem/home/oracle/execsql indicates that each hour is executed at 5 minutes/ home/oracle/execsql file 3, SQL and other commands that need to be run under specific environment variables must be listed in the execution file. For example, if sqlplus is executed in oracle, it must be written in the following format: $ cat execsql ORACLE_HOME =/ora815; export ORACLE_HOME ORACLE_OWNER = oracle; export ORACLE_OWNER ORACLE_SID = ora815; export ORACLE_SID ORACLE_BASE =/ora815/app/oralce; export ORACLE_BASE LD_LIBRARY_PATH = $ ORACLE_HOME/lib; export LD_LIBRARY_PATH PATH = $ PATH: $ ORACLE_HOME/bin: $ LD_LIBRARY_PATH; export PATH NLS_LANG = AMERICAN_AMERICA.ZHS16CGB231280; export NLS_LANG/ora815/bin/sqlplus t Est1/test1 @ test1.ext (execute the @ test1.ext file, and the database username/password is test1/test1) execsql is required to be an executable program $ ls-al execsql-rwxr-xr-x 1 oracle dba 374 Oct 07 execsql uses crontab, make the php program run at and modify it according to the following format. add it to crontab and set 00 0 * cd/your program path; php your program name. php requires cli or cgi mode for compiling.

In addition, if you do not have the management permission, only PHP functions in the virtual space are useful. This is gradually used in recent development. Int ignore_user_abort ([bool setting]) indicates whether the server continues to execute the following script after the remote client closes the connection. The setting parameter is an optional parameter. If it is set to True, it indicates that if the user stops running the script, the script is still not affected (that is, the script will be executed continuously); if it is set to False, the script stops running when the user stops running the script program.

Php background task execution code:

Sample code:

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.