As follows:
Copy codeThe Code is as follows:
<? Php
Header ('Context-Type: text/html; charset: gb2312 ;');
$ Urls = array (
'Http: // www.baidu.com /',
'Http: // www.pconline.com.cn /',
'Http: // www.163.com /'
);
$ Options = array (
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => array (
'Accept' => 'text/html, application/xhtml + xml ,',
'Accept-encoding' => 'gzip, deflate ',
'Accept-color' => 'zh-cn ',
'Connection' => 'keep-alive ',
'User-agent' => 'mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0 )',
),
);
Function curlMultiRequest ($ urls, $ options = array ()){
$ Ch = array ();
$ Results = array ();
$ Mh = curl_multi_init ();
Foreach ($ urls as $ key => $ val ){
$ Ch [$ key] = curl_init ();
If ($ options ){
Curl_setopt_array ($ ch [$ key], $ options );
}
Curl_setopt ($ ch [$ key], CURLOPT_URL, $ val );
Curl_multi_add_handle ($ mh, $ ch [$ key]);
}
$ Running = null;
Do {
Curl_multi_exec ($ mh, $ running );
} While ($ running> 0 );
Foreach ($ ch as $ key => $ val ){
// $ Results [$ key] = iconv ('gb2312', 'utf-8', curl_multi_getcontent ($ val ));
$ Results [$ key] = curl_multi_getcontent ($ val );
Curl_multi_remove_handle ($ mh, $ val );
Curl_close ($ val );
}
Curl_multi_close ($ mh );
Return $ results;
}
$ Results = curlMultiRequest ($ urls, $ options );
Print_r ($ results );
?>