How to use php for Linux automatic script execution?

Source: Internet
Author: User
Tags html header
Article Title: how to use php for Linux automatic script execution ?. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Summary
  
?? In Linux, crontab is a command for scheduled execution. with this command, we can regularly execute a PHP file to implement automatic execution of scripts in Linux using PHP.
?? How to use PHP for Linux automatic script execution?
  
?? When installing PHP, an executable file is generated, named php. copy it to/usr/local/bin. run the php program on the terminal:
  
???? Php-q onlinnum. php
  
Is PHP originally used for webpage applications? So it will send the html header? But here we want to use PHP as a Shell Script? "-Q" means not to send the HEADER. you can try not to add the "-q" Display result. Now you can execute PHP code in the terminal mode. ?? Linux command: cron daemon
  
?? This is a resident service in the 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 be executed. all outputs are sent to the user by mail.
  
?? Set crontab
?? Command: crontab-e
  
?? This command calls the vi editor to edit the execution list. For example
  
?? 0 0 1, 15 ** fsck/home
?? 1 ***/home/myhome/printhello
  
?? Each row represents a scheduled task. it is a scheduled time before the command. There are a total of five columns separated by spaces, sorted from left to right as follows:
  
?? --------------------------
?? Minutes from 00 to 99
?? From 0 to 24 o'clock
?? From 01 to 31
?? From 01 to 12 months
?? The week ranges from 01 to 07, representing Monday to Sunday.
?? * Indicates "every". if it is executed every day, enter * in the third column.
?? --------------------------
?? So the two tasks in the above example are:
?? Check/home disk on the 1st and 15th of each month
?? Run the/home/myhome/printhello file in the first hour.
  
?? View crontab: crontab-l
?? Delete crontab: crontab-r
  
?? We will know how to use the PHP and crontab commands to execute scripts automatically in Linux.
  
?? What else do you need to pay attention?
  
?? If a database is used in php, such as oracle, you also need to set the export Oracle environment in the execution script. Because the script execution in cron is performed without logon, many environment variable values set in the system are missing, and problems may occur when connecting to the database.
  

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.