/** 同时打开多个URL */ function get_urls(u r l s , urls,urls,per=10,$try=1){ h e a d e r s [ ] = ′ U s e r − A g e n t : ′ . headers[] = 'User-Agent: '.headers[]= ′ User−Agent: ′ ._SERVER[‘HTTP_USER_AGENT’]; $headers[] = ‘Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8’; $headers[] = ‘Accept-Language: zh-cn,zh;q=0.5’; $headers[] = ‘Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7’; $headers[] = ‘Keep-Alive: 115’; h e a d e r s [ ] = ′ C o n n e c t i o n : k e e p − a l i v e ′ ; / / headers[] = 'Connection: keep-alive'; //headers[]= ′ Connection:keep−alive ′ ;//headers[] = 'Cookie: '.$cookie_file; //$m_cookie_name = $this->get_content_cookie_path(); o p t i o n s = a r r a y ( C U R L O P T H T T P H E A D E R = > options=array( CURLOPT_HTTPHEADER=>options=array(CURLOPT H TTPHEADER=>headers, CURLOPT_SSL_VERIFYHOST=>FALSE, CURLOPT_SSL_VERIFYPEER=>FALSE, CURLOPT_COOKIEFILE=>m c o o k i e n a m e , C U R L O P T C O O K I E J A R = > m_cookie_name, CURLOPT_COOKIEJAR=>m c ookie n ame,CURLOPT C OOKIEJAR=>m_cookie_name, ); u r l s 2 = a r r a y ( ) ; f o r e a c h ( urls2=array(); foreach(urls2=array();foreach(urls as k = > k=>k=>v){ u r l s [ urls[urls[k]= t h i s − > g e t u r l ( this->get_url(this−>get u rl(v); } while(count(u r l s ) ) urls))urls))urls2[] = array_splice(u r l s , 0 , urls,0,urls,0,per); $errorUrls=array(); d a t a s = a r r a y ( ) ; f o r e a c h ( datas = array(); foreach(datas=array();foreach(urls2 as u k = > uk=>uk=>url2s){ m = n e w H t t p M u l t i R e q u e s t ( m = new Http_MultiRequest(m=newHttp M ultiRequest(options); m − > s e t U r l s ( m->setUrls(m−>setUrls(url2s); $data = $m->exec(); i n f o s = ( infos = (infos=(m->getInfos()); foreach($infos as i k = > ik=>ik=>info){ if($info[‘http_code’]!=200){ e r r o r U r l s [ errorUrls[errorUrls[ik]=u r l 2 s [ url2s[url2s[ik]; echo i k . ′ h t t p c o d e : ′ . ik.' http_code:'.ik. ′ http c ode: ′ .info[‘http_code’].’ ’; } } d a t a s = a r r a y m e r g e ( datas =array_merge (datas=array m erge(datas, KaTeX parse error: Expected 'EOF', got '}' at position 10: data); }̲ //echo'Error…errorUrls); if(KaTeX parse error: Expected 'EOF', got '&' at position 10: errorUrls&̲&try>0){ d a t a = g e t u r l s ( data = get_urls(data=get u rls(errorUrls,p e r , per,per,try-1); d a t a s = a r r a y m e r g e ( datas =array_merge (datas=array m erge(datas, $data); } return $datas; } ———————————————— 版权声明:本文为CSDN博主「是有头发的程序猿」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/wbryze/article/details/116584716