我用php模拟的多线程,做的一个采集,大概采集30个页面 要30秒左右,如何提高效率?多线程函数如下:function create_curl($url_list)
{
   
     $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://dev.sanbobotool.com/update_information/thread_new.php');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $url_list);
return $ch;


}//curl实现的线程函数
function curl_runThread($url_list)
{
$ret = array();
$mh = curl_multi_init();
for ($i=0;$i<=29;$i++) 
{
    $ch[$i] = create_curl($url_list[$i]);
    //加上资源句柄
    curl_multi_add_handle($mh,$ch[$i]);
}

//预定义状态变量
$active = null;

// 3. 初始处理
do 
{
    $mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active&&$mrc==CURLM_OK)
{
if (curl_multi_select($mh) != -1) 
{
 // 6. 干活
        do {
             $mrc = curl_multi_exec($mh, $active);
           }while ($mrc == CURLM_CALL_MULTI_PERFORM);

           
        
}
}

//关闭各个句柄
for($i=0;$i<=29;$i++)
{
$ret_center = curl_multi_getcontent($ch[$i]);
if($ret_center!="0")
$ret[] = $ret_center;
curl_multi_remove_handle($mh, $ch[$i]);
}

curl_multi_close($mh);
return $ret;
}thread_new.php 是运行子线程的页面采集页面的函数 都和下面的函数差不多
//当当的商品价格检测
function check_price_dd($url,$offer_id,$g_type,$bef_price,$i)
{
$price = "";
$body = file_get_html($url)->getElementByTagName('body');
if(empty($body))
return 0;
switch($g_type)
{
case 1:
if($body->getElementByTagName('p[class="price_d"]'))
{
$item = $body->getElementByTagName('p[class="price_d"]');
if($item->getElementByTagName('span[class="num"]'))
$price = $item->getElementByTagName('span[class="num"]')->plaintext;
}
break;
case 2:
case 3:
case 5:
case 4:
case 6:
case 7:
case 9:
case 23:
if( $body->getElementById('salePriceTag'))
{
$item = $body->getElementById('salePriceTag');
$price = $item->plaintext;
}
break;
case 8:
if($body->getElementByTagName('span[class="promotions_price_d"]'))
{
$item=$body->getElementByTagName('span[class="promotions_price_d"]');
if($item->getElementByTagName('b'))
$price = $item->getElementByTagName('b')->plaintext;

}
else
{
if($body->getElementById('salePriceTag'))
{
$item = $body->getElementById('salePriceTag');
$price = $item->plaintext;
}
}
break;
default:
break;

}
 $price = preg_replace('/[^\d|.]+/','',$price);

if($price!="")
{

if($price!=$bef_price)
{
return $price."@".$offer_id;
} }

return 0;

}