Linux timed execution php file instance program

Source: Internet
Author: User


After trying in Linux

Crontab-e

Direct edit

0 * * */usr/bin/php/var/www/html/business/crontab.php

If you have require other files in your crontab.php, execution may be problematic, so it is recommended that you do not use this method.
We can do this:

First set up in one place. SH Shell file is a new crontab.sh file than I did under/root/shell. Write:

#!/bin/sh
/usr/bin/links-source/crontab.php

Then add the entries in the CRONTAB-E

0 * * */bin/bash/root/shell/crontab.sh

This will be OK, every day at 11 o ' The file will be executed!

Time rule with crontab instruction

The order and value range of five fields and their meanings are:

0~59-
1~23 means hours
1~31 said Day
1~12 represents the Month
0~6 said week (of which 0 said Sunday)


If you are using a task that is not executed in hourly monthly weekly, you can write the corresponding crontab to the crontab or CRON.D directory.

Example:

Perform a script every minute/opt/bin/test-cron.sh
You can create a new script in CRON.D echo-date.sh
Content is

*/1 * * * * root/opt/bin/test-cron.sh

Execute PHP Script

Method 1

If you want to execute a PHP script on a regular basis, you can write it directly:
*/1 * * * * * root-q/bin/local/php/path/to/your/php/script.php (script.php per minute)
Note that you need to turn PHP into an executable script file. At the command line, the directory where the script resides

chmod +x script.php

Example 1

Execute PHP scripts regularly under Linux

Write in the normal way
? Php

$file = '/htdocs/www/b100/egspace/bin/test/'. Date (' H '). -'. Date (' I '). -'. Date (' s '). TXT ';
File_put_contents ($file, date (' y-m-d '));
?>

Change the PHP file attribute to a shell file:

chmod +x test.php

Re-edit crontab:

Crontab-e

Add one line:

*/1 * * * */usr/local/bin/php-q/htdocs/www/b100/egspace/bin/test.php

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.