Use php for linux automatic script execution (ha, super easy to use ). Recently, I used PHP as a community. when I wrote the code to calculate the maximum number of online users, I successfully debugged the code to run PHP directly on the server as a shellscript. when working in the community, it is often necessary to count the number of people going online and so on. recently, using PHP as a community, when writing to calculate the maximum number of people going online, after successful debugging, PHP is run 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. generally, this code is stored in the user login or a page to trigger the code when the user logs on or accesses the page. in this way, a problem occurs. if the code is complicated, the normal call speed of the page is obviously slowed down.
With this feature of PHP and the linux crontab command, you can automatically and periodically execute a PHP file (count the number of online users ).
Specific method:
When installing PHP, an executable file is generated, named php. copy the file to/usr/local/bin.
Run the php program in the terminal mode: php-q onlinnum. php
Note that PHP is originally used for webpage application, so it will certainly send html header encoding. However, here we want to use PHP as a Shell Script handler "-q" to indicate that no HEADER should be sent. meaning. you can try not to add the result of-q.
Now you can run the 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/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:
Field description
--------------------------
Minutes from 00 to 99
From 0 to 24 o'clock
From 01 to 31
From 01 to 12 months
When writing to the computing maximum number of online users, you can successfully debug and run PHP directly on the server as a shell script. when working as a community, you often need to count the number of online users...