Home >Backend Development >PHP Tutorial > php curl 多线程抓取数据会判断分别来自哪个url吗

php curl 多线程抓取数据会判断分别来自哪个url吗

WBOY
WBOYOriginal
2016-06-13 12:47:06748browse

php curl 多线程抓取数据能判断分别来自哪个url吗?

 $mh = curl_multi_init(); // 开启多线程<br />
<br />
    $i = 0;<br />
    foreach($url_array as $url) {<br />
        $ch = curl_init();<br />
	    if (IS_PROXY) {<br />
			curl_setopt ($ch, CURLOPT_PROXY,'67.215.228.129:8089' );//60.12.226.18<br />
		} <br />
        curl_setopt($ch, CURLOPT_URL, $url);<br />
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return don't print<br />
        curl_setopt($ch, CURLOPT_TIMEOUT, 30); //设置超时时间<br />
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');<br />
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // 302 redirect<br />
        curl_setopt($ch, CURLOPT_MAXREDIRS, 7); //HTTp定向级别<br />
        curl_multi_add_handle($mh, $ch); // 把 curl resource 放进 multi curl handler 里<br />
        $handle[$i++] = $ch;<br />
    }


代码如上,开启多线程抓取数据;假如我一次加入10个url,返回给我的是一个有10个结果的数组。我不能判断这些数据分别是来自哪个url的。
请问有什么办法,还是其他哪种语言能实现,多线程抓取的数据还知道来自哪个url的。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn