KeywordsUsing PHP as a Linux automatic execution script
Using PHP as a community, when written to calculate the highest number of people, successfully debug the PHP as the shell Script runs directly on the server.
When making a community, it is often necessary to count data such as the number of people on the line. The general practice is to put this code in the user
Login or a page that triggers the code to run when the user logs on or accesses it. Such
One can cause a problem if the code teaches complexity and significantly slows down the normal invocation speed of the page.
With this feature of PHP, plus the Linux crontab instructions, you can automatically schedule a PHP text
(Count online numbers, etc.).
Specific methods:
When you install PHP, an executable file is generated with the file name PHP. copy it to/usr/local/bin
Under.
Execute PHP Program in terminal mode: Php-q onlinnum.php
Notice that PHP was originally applied to a Web page, so it would send HTML
header, But here we are going to use PHP as Shell script, "-Q" means not to send out
The meaning of 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. Oh, you can try to do what you wrote before.
Code.
Linux command: Cron daemon
This is a resident service in a system that performs routine work, such as once a day or a monthly
Check the disk again. Cron Daemon will check the scheduled worksheets (crontab) every minute to see
To see if there are instructions to execute, all output will be 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
&nbs p; 0 0 1,15 * * fsck/home
&nbs p; 1 * * * */home/gull/onlinnumber
Each row represents a scheduled work, with a total of 5 fields, with a space in front of the instruction, for the scheduled time
Interval, from left to right in the following sequence:
Field &nbs p; Description
---------------------- ----
Minutes from 00 to 99
o ' clock from 0 to 24
Day &nbs p; from 01 to 31
Month &nbs p; 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/gull/onlinnumber this file
View Crontab:crontab-l
Delete Crontab:crontab-r
Oh, here, you should know how to use PHP and crontab command to count the number of people online?
Need to note:
If you have a database in PHP, such as Oracle, you need to export Oracle's environment in the execution script
Reset Because the script executed under Cron is executed without logging in, there are fewer systems
Set the value of the environment variable, when connected to the database will be asked
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.