Php uses the curl proxy to capture data.
This example describes how php uses the curl proxy to capture data. We will share this with you for your reference. The details are as follows:
<? Phpdefine ('is _ proxy', true); // whether to enable PROXY function async_get_url ($ url_array, $ wait_usec = 0) {if (! Is_array ($ url_array) return false; $ wait_usec = intval ($ wait_usec); $ data = array (); $ handle = array (); $ running = 0; $ mh = curl_multi_init (); // enable multithreading $ I = 0; foreach ($ url_array as $ url) {$ ch = curl_init (); if (IS_PROXY) {// The following Code sets the proxy server address http://www.cnproxy.com/proxy1.html !! Hong Kong and China have a better speed than curl_setopt ($ ch, CURLOPT_PROXY, '2017. 4.12.170: 80');} curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // return don't print curl_setopt ($ ch, CURLOPT_TIMEOUT, 30); // set the timeout value curl_setopt ($ ch, CURLOPT_USERAGENT, 'mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) '); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); // 302 redirect curl_setopt ($ ch, C URLOPT_MAXREDIRS, 7); // HTTp Targeting level curl_multi_add_handle ($ mh, $ ch ); // put curl resource into multi curl handler $ handle [$ I ++] = $ ch;}/* execute */do {$ mrc = curl_multi_exec ($ mh, $ running); if ($ wait_usec> 0)/* how long each connect interval */usleep ($ wait_usec ); // 250000 = 0.25 sec} while ($ mrc = CURLM_CALL_MULTI_PERFORM); while ($ running & $ mrc = CURLM_ OK) {if (curl_multi_select ($ mh )! =-1) {do {$ mrc = curl_multi_exec ($ mh, $ running);} while ($ mrc = CURLM_CALL_MULTI_PERFORM );}} /* read data */foreach ($ handle as $ I => $ ch) {$ content = curl_multi_getcontent ($ ch ); $ data [$ I] = (curl_errno ($ ch) = 0 )? $ Content: false;}/* remove handle */foreach ($ handle as $ ch) {curl_multi_remove_handle ($ mh, $ ch);} curl_multi_close ($ mh ); return $ data ;}$ urls = array ('HTTP: // map.baidu.com '); $ re = async_get_url ($ urls); echo $ re [0];?>