Using PHP as a Linux automatic execution script
[Source] Dahne [edit] Dahne [Time]2013-03-21
When making a community, it is often necessary to count data such as the number of people on the line. It is a common practice to put this code on a user login or a page to trigger the code to run when the user logs on or accesses it. This can cause a problem if the code teaches complexity and significantly slows down the normal invocation speed of the page.
Recently in PHP (PHP training PHP tutorial) as a community, when written to calculate the maximum number of people, successfully debug the PHP as a shell script directly on the server run.
When making a community, it is often necessary to count data such as the number of people on the line. It is a common practice to put this code on a user login or a page to trigger the code to run when the user logs on or accesses it. This 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 crontab instruction of Linux (Linux Tutorial Linux Training), a PHP file can be executed automatically (counting the number of people online).
Specific methods:
When you install PHP, an executable file is generated with the file name PHP. copy it to/usr/local/bin.
Execute PHP Program in terminal mode: Php-q onlinnum.php
Notice that PHP was originally applied to the Web application, so it will send out the HTML header, but here we are 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. Oh, you can try to execute the code you wrote before.
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
&nbs p; 0 0 1,15 * * fsck/home
&nbs p; 1 * * * */home/gull/onlinnumber
Each row represents a scheduled work
Using PHP as a Linux automatic execution script