Scheduled execution of PHP files in Linux

Source: Internet
Author: User

The previous article mentioned the use of the crontab timer. Here is a brief introduction

SHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=rootHOME=/# run-parts01 * * * * root run-parts /etc/cron.hourly02 4 * * * root run-parts /etc/cron.daily22 4 * * 0 root run-parts /etc/cron.weekly42 4 1 * * root run-parts /etc/cron.monthly01 8 * * * root /home/www/db_back/bk.sh10 8 * * * root /opt/lampp/bin/php /home/www/deleteOldDB.php 

/Opt/lampp/bin/PHP is your PHP installation directory. You can set it based on your server.

You can first try to execute the. php file in the shell on your server. If so, this directory can be used.

Such as: CD/opt/lampp/bin press ENTER

XXXXX $:./PHP/var/www/test. php

If this command can be executed, you can use this directory. Different server versions have different directories,
Ubuntu can be used only when php5-cli is installed.

Then you can edit the crontab file. The code above VI/etc/crontab is.

I have a lot of online information about # bath... and so on in the PHP file. I tried it and can execute it without adding it ,.

/Opt/lampp/bin/PHP: the PHP Execution file to this directory. Use this file to execute the absolute target. php file, such as the/home/www/deleteolddb. php file.

You can also access the directory XXXX #: CD/opt/lampp/bin/PHP in shell and enter./PHP/home/www/deleteolddb. php.

In this way, you can access the PHP file. If you cannot access the PHP file here, the scheduled execution will not be able to be executed. (Transfer)


PS:

1. If php references other PHP files, such as Conn to connect to the database. INC, the path must be an absolute path (/home/workpath/phproject /... /Conn. INC). Otherwise, an error may occur. It may be that the scheduled task can only read the absolute path!

2. When you set a scheduled task, run the/etc/init. d/cron restart command to restart the timer.

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.