php同时下载多条URL函数

时间:15-07-13 栏目:网站开发 作者:admin 评论:0 点击: 2,263 次

php同时下载多条URL函数

	/**
	* 同时打开多个URL
	*/
	function get_urls($urls,$per=10,$try=1){

		$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';
		$headers[] = 'Connection: keep-alive';
		//$headers[] = 'Cookie: '.$cookie_file;

		//$m_cookie_name	= $this->get_content_cookie_path();
		$options=array(
			CURLOPT_HTTPHEADER=>$headers,
			CURLOPT_SSL_VERIFYHOST=>FALSE,
			CURLOPT_SSL_VERIFYPEER=>FALSE,
			CURLOPT_COOKIEFILE=>$m_cookie_name,
			CURLOPT_COOKIEJAR=>$m_cookie_name,
		);

		$urls2=array();
		foreach($urls as $k=>$v){
			$urls[$k]= $this->get_url($v);
		}
		while(count($urls))$urls2[] = array_splice($urls,0,$per);		

		$errorUrls=array();
		$datas = array();
		foreach($urls2 as $uk=>$url2s){
			$m = new Http_MultiRequest($options);
			$m->setUrls($url2s);
			$data = $m->exec();
			$infos = ($m->getInfos());
			foreach($infos as $ik=>$info){
				if($info['http_code']!=200){
					$errorUrls[$ik]=$url2s[$ik];
					echo $ik.' http_code:'.$info['http_code'].'<br>';
				}
			}
			$datas =array_merge ($datas, $data);
		}
		//echo'ErrorUrls:';pecho($errorUrls);
		if($errorUrls&&$try>0){
			$data = get_urls($errorUrls,$per,$try-1);
			$datas =array_merge ($datas, $data);

		}
		return $datas;

	}

声明: 本文由( admin )原创编译,转载请保留链接: php同时下载多条URL函数

php同时下载多条URL函数:等您坐沙发呢!

发表评论


------====== 本站公告 ======------
联系信息:
lxq73061#qq.com qq:583964941
支付宝:https://me.alipay.com/lxq73061
相关插件程序等信息均会在站内发布,敬请关注。

读者排行