How PHP implements Web page close not stop script

Source: Internet
Author: User
Tags stop script
How does PHP implement Web page close without stopping the script? This paper mainly introduces the method of PHP offline execution after the webpage is closed, which has a good reference value. We hope to help you.

Directly on the code, the main function

Ignore_user_abort (TRUE);

This function ignores the terminal being closed (the Open Web page is closed), the back

GetFiles () This function is a custom function that performs the acquisition task, followed by the next path

Open the written page, close, after the discovery of the task can be completed, interested can try.

<?php//setting ignores whether to close the terminal window Ignore_user_abort (true); Ini_set (' Max_execution_time ', ' 0 ');//Collect page functions, do not understand the implementation of Baidu Curl Phpfunction GetFiles ($url, $name) {  $name = $name. ". TXT ";  $ch = Curl_init ("$url");  $fp = fopen ("$name", "w");  curl_setopt ($ch, Curlopt_file, $fp);  curl_setopt ($ch, Curlopt_header, 0);  Curl_exec ($ch);  Curl_close ($ch);  Fclose ($FP);  Sleep (5);  Echo ' <script>window.close ();</script> ';} Configure an array of page paths to be collected $urls = Array (  ' http://www.***.com/jiag/p/6373168.html ',  ' http://***.com/a/20170218/ 029521.htm ');//Traversal array foreach ($urls as $key = = $val) {  GetFiles ($val, $key);}? >

Related recommendations:

PHP features a powerful Curl post class

PHP learns Curl's crawler instances

PHP Curl Camouflage Source information

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.