Using PHP as a community, when writing to calculate the maximum number of people going online, the system successfully debugged and used PHP as shellscript to run directly on the server. when working in the community, it is often necessary to count the number of online users and other data. the general practice is to put this code in the user login or
Using PHP as a community, when writing to calculate the maximum number of people going online, we successfully debugged and run PHP directly on the server as a shell script. when working in the community, it is often necessary to count the number of online users and other data. the general practice is to place this code in the user's login or a page, so that the code can be triggered when the user logs on or visits this page. in this way, a title is generated. if the code is complicated, the normal call speed of the page is obviously slowed down. using this feature of PHP and the Linux crontab command, you can actively perform a certain PHP file (counting the number of online users, etc.) on a regular basis ).
Specific method:
When installing PHP, an executable file is generated, named php. copy it to/usr/local/bin.
Execute the php program in the terminal method: php-q onlinnum. php
Note that the PHP base is used on a webpage, so it will certainly send the html header, but here we want to use PHP as a Shell Script, '-Q' means the performance is not to be sent the meaning of the output HEADER. you can try not to add the result of-q.
Now you can execute the PHP code in the terminal method.
Code.
Linux command: cron daemon
This is a resident service in the system. its function is to perform 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 compile the list of executions. For example
& Nbs p; 0 0 ** fsck/home
& Nbs p; 1 *****/home/Gull/onlinnumber
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:
Column & nbs p; clarification
--------------------------
Minutes from 00 to 99
From 0 to 24 o'clock
Day & nbs p; from 01 to 31
Month & nbs p; from 01 to 12
The week ranges from 01 to 07, representing Monday to Sunday.
* Indicates the performance of "every". for example, if the performance is performed 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
Perform the/home/Gull/onlinnumber file in the first hour
View crontab: crontab-l
Delete crontab: crontab-r
Well, here, you should know how to use the PHP and crontab commands to count the number of online users?
Note:
If php has an application database, such as oracle, you also need to configure the export Oracle environment in the execution script. Because the script execution in cron is performed by users without logging on to the database, many environment variables set in the system are missing. when you connect to the database, you will be asked