我想点击网址并使用curl传递用户名并最终获得回复。我面临的问题是我的用户名数组有大约45000个条目。我尝试使用curl_multi_init实现它但不幸的是它仅适用于小块数据最多同时为15个请求,否则对于整个数组,页面会一直加载和加载,有时它会给出内存限制错误,即内存不足(分配30408704)(尝试分配65536字节)。
foreach($username as $u)
{
$data[]='http://cba.com.pk/hxc/get_details.php?uname='.$u;
}
function multiRequest($data)
{
$curly = array();
$result = array();
$mh = curl_multi_init();
$ua = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13';
foreach ($data as $id => $d)
{
$curly[$id]= curl_init();
curl_setopt($curly[$id], CURLOPT_URL,$d);
curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER,true);
curl_setopt($curly[$id], CURLOPT_USERAGENT, $ua);
curl_setopt($curly[$id], CURLOPT_AUTOREFERER, true);
curl_setopt($curly[$id], CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curly[$id], CURLOPT_MAXREDIRS, 20);
curl_setopt($curly[$id], CURLOPT_HTTPGET, true);
curl_setopt($curly[$id], CURLOPT_HEADER,0);
curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER,1);
curl_multi_add_handle($mh, $curly[$id]);
}
$running = null;
do
{
curl_multi_exec($mh, $running);
} while ($running);
foreach($curly as $id => $c)
{
$result[$id] = curl_multi_getcontent($c);
curl_multi_remove_handle($mh, $c);
}
curl_multi_close($mh);
return $result;