PHP Linux timed task settings

Source: Internet
Author: User

1. crontab cannot save run Select-editor Select the second nano ... Then run CRONTAB-E according to the following prompts ^o write and ^x exit the program. Or select 3, use Vim to edit the configuration steps: 1. Linux must be compiled to install the PHP interpreter, after the installation is complete, to copy the installation directory under the ${php}/bin/php file under/usr/bin/, and use chmod +x./php Add executable permissions for it, OK, and then enter it on the Linux command line: PHP -Q *.php executes a PHP program to verify that the interpreter is working properly 2. Publish PHP Files: Publish the written PHP program to the Apache publishing directory: such as:/var/www/html under the permission: chmod +x/var/www/html/*. PhP3. Create a timed task: (1) Start Linux Timer service: Service Crond Start (2) View current scheduled task: Crontab-l (3) Add new Timer task: CRONTAB-E Edit in Open file: */2 * * * */usr /bin/php-f/var/www/html/*.php indicates that/var/www/html/*.php files are executed every 2 minutes * * * * * * /usr/bin/php-f/var/www/222.com/www/ipphone/timingcall.php perform a total of 60 times from 11 o'clock to 12 in the evening.* * * * * /usr/bin/php-f/var/www/222.com/www/ipphone/timingcall.phpexecuted 1 times in the evening 11:01(Note:-F is important and cannot be modified to-Q) 4. How to verify that the crontab file exists if CRONTAB-E is unsuccessful, modify the command in the/var/spool/cron/crontabs user fileTo verify that the user's crontab file exists, use the Ls-l command in the/var/spool/cron/crontabs directory
    5       *       *           *     *     LS             Specify 5 minutes per hour to execute the LS command     &nbsp     5     ; *           *     *     LS             to specify 5 per day: 30 Execute LS command         7       8         *     *   &NBS P LS             Specify 7:30 minutes of 8th per month to execute the LS command         5       8 &NB Sp       6     *                 To specify the June 8 5:30 to execute the LS command &nbsp ;       6       *           *     0     LS &NB Sp           Specify 6:30 execute ls command per Sunday [Note: 0 for Sunday, 1 for week 1,    and so on, can also be expressed in English, Sun says Sunday, Mon for Monday, etc. ]       3     10,20     *     *     LS     Monthly # 10th and 20th 3:30 execute LS command [Note: "," used to connect multiple discontinuous periods]        8-11 *           *     *   &NBSP ; LS       8-11-point 25-minute execution of the LS command [note: "-" used to connect consecutive periods]    */15   *       *   &NBSP ;       *     *     LS         15-minute execution of the LS command [i.e. No. 0 15 30 45 60 minutes per hour Line ls command]     30   6     */10         *     *     LS & nbsp     The LS command is executed every 10 days 6:30 each month [i.e., 1, 11, 21, 31st, 6:30 executes the LS command once. ]      Performs all executables in the/etc/cron.daily directory as root 7:50 daily      50   7       * &nbs P           *     *     root     run-parts    /etc/cron.da ily   [Note: The Run-parts parameter indicates that all executables in the following directory are executed. ]

crontab-u//Set a user's Cron service, which is usually required by the root user when executing this command

CRONTAB-L//list details of a user cron service

Crontab-r//Delete a cron service with no users

CRONTAB-E//Edit a user's cron service

For example, root to view your cron settings: crontab-u root-l

Again, for example, Root wants to delete Fred's cron settings: Crontab-u fred-r

When editing the Cron service, the edited content has some formatting and conventions, input: Crontab-u root-e

Enter VI edit mode, the content of the edits must conform to the following format: */1 * * * * ls >>/tmp/ls.txt

The first part of this format is the time setting, the next part is the command to execute, if you want to execute too many commands, you can write these commands into a script, and then call this script directly here, you can recall the full path of the command when the call. Time setting we have a certain agreement, the preceding five * number represents five numbers, the value range and meaning of the numbers are as follows:

Minutes (0-59)

Hours (0-23)

Date (1-31)

Month (1-12)

Week (0-6)//0 representative Sunday

In addition to the numbers there are several special symbols are "*", "/" and "-", ",", * represents all the values within the range of the number, "/" for each meaning, "*/5" means every 5 units, "-" represents from a number to a number, "," separate several discrete numbers. Here are a few examples to illustrate the problem:

Every morning at 6.

0 6 * * echo "Good morning." >>/tmp/test.txt//Note simply Echo, no output is visible from the screen, because cron emails any output to root .

Every two hours

0 */2 * * echo "has a break now." >>/tmp/test.txt

Every two hours between 11 o'clock and 8 in the morning, eight in the morning.

0 23-7/2,8 * * * echo "a good Dream:)" >>/tmp/test.txt

Every month, number 4th and Monday to Sunday, three a.m., 11.

0 4 * 1-3 command Lin

January 1 morning, 4.

0 4 1 1 * command line

after editing a user's cron settings, Cron automatically generates a file with the same name as the user under/var/spool/cron, and the cron information for this user is recorded in this file, which cannot be edited directly and can only be edited with CRONTAB-E. After Cron starts, read the file once every one of the clocks, and check to see if you want to execute the command inside. Therefore, the Cron service does not need to be restarted after this file has been modified


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.