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