Using PHP as a community, when writing to calculate the highest number of online, successfully debug the PHP as a shell script directly on the server running. When you are a community, you often need to count data on the number of online people. As a general practice, place the code in a user login or a page that triggers the code to run when the user logs in or accesses it. This creates a problem that, if the code is taught complex, slows down the normal call speed of the page. With this feature of PHP, plus Linux crontab instructions, you can automatically timed a PHP file (statistics online number of people, etc.).
Specific methods:
When you install PHP, you produce an executable file named PHP. copy it to/usr/local/bin.
Execute PHP Program in terminal mode: Php-q onlinnum.php<enter>
Note that PHP was originally applied to web applications, so it will send out HTML header, But here we are using PHP as Shell script, "-Q" means not to send headers. You can try not to add-Q display results.
At this point you can already execute the PHP code in the terminal mode. Oh, you can try to carry out your previous written
Code.
Linux command: Cron daemon
This is a resident service in a system that performs routine work, such as checking the disk once a day or once a month. Cron Daemon will check the scheduled worksheets (crontab) every minute to see if there are any instructions to execute, and all output will be sent to the user in mail.
Set crontab
Command:crontab-e<enter>
This command calls the VI Editor to edit the execution manifest. 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, separated by spaces, from left to right, at the scheduled time before the instruction:
Field &nbs p; Description
---------------------- ----
Minutes from 00 to 99
At seven 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
* sign "every", if executed every day, fill in the third column * number
So the two tasks in the previous example are:
1th and 15th monthly check/home disk
The first minute of every hour executes/home/gull/onlinnumber this file
View Crontab:crontab-l<enter>
Delete crontab:crontab-r<enter>
Oh, here, you should know how to use the PHP and crontab command to count the number of online?
Need to note:
If you have a database in PHP that uses databases such as Oracle, you will need to export Oracle's environment settings in the execution script. Because the user of the script executed under Cron is executed in no login state, the value of the environment variable set in the system is less, and the database will be asked