Use PHP as a Linux auto-execute script (hehe, super-easy function) _php Tutorial

Source: Internet
Author: User
Tags html header
Recently in a community with PHP, writing to calculate the highest 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 Linux crontab instructions, you can automatically schedule a php file (counting 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.
Execute PHP Program in terminal mode: Php-q onlinnum.php
Note that PHP was originally applied to the Web application of the ╋ 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 meaning. 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
0 0 1,15 * * Fsck/home
1 * * * */home/gull/onlinnumber
Each row represents a scheduled work, a total of 5 fields are scheduled before the instruction, with a space interval, from left to right as Next:
Field description
--------------------------
minutes from 00 to 01
o ' clock from 0 to ~
Day from 01 to ~
Month (

)

http://www.bkjia.com/phpjc/445240.html www.bkjia.com true http://www.bkjia.com/phpjc/445240.html techarticle recently in PHP as a community, when written to calculate the highest number of people, successfully debug the PHP as a shell script directly on the server run. When you're a community, Always need to count the number of people on the line ...

  • Related Article

    Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.