How to use PHP as a Linux auto-execute script _php tutorial

Source: Internet
Author: User
Tags install php html header
Review
Linux crontab is the implementation of timed execution of instructions, using this command we can execute a certain PHP file at a time, so that the implementation of PHP as a Linux automatic script execution.
How to use PHP as a Linux automatic script execution?
When you install PHP, you generate an executable file named PHP. copy it to/usr/local/bin. Execute PHP Program in terminal mode:
Php-q onlinnum.php
PHP was originally applied to web applications, so it would send out HTML header, But here we are going to use PHP as the Shell script, "-Q" means not to send out the HEADER. You can try not to add the "-Q" Display results. At this point you can already execute the PHP code in the terminal mode. Linux command: Cron daemon
This is a resident service in a system that performs routine work, such as checking disks once a day or once a month. Cron Daemon checks the scheduled worksheet (crontab) every minute to see if there are instructions to execute, and all the output is sent to the user in mail.
Set crontab
Command: CRONTAB-E
This command calls the VI Editor to edit the list of executions. For example
0 0 1,15 * * fsck/home
1 * * * */home/myhome/printhello
Each row represents a scheduled work, with a total of 5 fields at the scheduled time before the instruction, with a space interval, from left to right, as follows:
--------------------------
Minutes from 00 to 99
o ' clock from 0 to 24
Day from 01 to 31
Months from 01 to 12
Week from 01 to 07, representing Monday to Sunday
* Number means "every", such as daily execution, in the third column fill in the * number
--------------------------
So the two tasks in the example above are:
Check/home disk 1th and 15th per month

The first minute of every hour executes/home/myhome/printhello this file
View Crontab:crontab-l
Delete Crontab:crontab-r
We know how to use PHP and the crontab command as a Linux autorun script.
What else do you need to be aware of?
If you have a database in PHP, such as Oracle, you also need to export Oracle's environment settings in the script execution. Because the script executed under Cron is executed without logging in, there are fewer environment variables set in the system, and there are problems when connecting to the database.

http://www.bkjia.com/PHPjc/531814.html www.bkjia.com true http://www.bkjia.com/PHPjc/531814.html techarticle crontab in Linux is an instruction to implement timed execution, which allows us to execute a PHP file on a timed basis to implement a Linux automated script using 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.