PHP program background execution

Source: Internet
Author: User
Generally, the PHP program must be triggered when the browser opens the page. The following method can be used to start the PHP program on page B on page. In addition, after page a is closed, page B does not stop running until the program on page B is completed.
The Code is as follows:
Code of page:
<? PHP
$ Fp = fsockopen ("localhost", 80, $ errno, $ errmsg );
Fputs ($ FP, "get/test. phprnrn ");
Fclose ($ FP );
?>
Code of page B (Suppose the file name of page B is test. php ):
<? PHP
$ Fp = fopen(”test.txt "," W ");
For ($ I = 0; $ I & lt; 10000000; $ I ++ ){
Fwrite ($ FP, "");
}
Fclose ($ FP );
?>
Open page A in the browser and you can see that page a is executed soon. After that, we can see that the test.txt file opened on page B keeps growing until the execution of page B is complete.
This method can be used to generate static pages in the system where you need to generate static pages. In addition, the execution of page B does not affect the execution of page; if you want to update data regularly but do not want the update program to affect user browsing, you can start page B to update data when Browsing page.

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.