为什么下面的这段代码 有的时候可以测试成功 有的时候又不可以呢?请教高手如果改正 让这个PHP代码更加稳定一些 <?php
$url_b='http://item.taobao.com/auction/item_detail-0db1-0f0c97e6d4b30c7218708c9c6d2ced23.jhtml';
if ($url_b =='') die("地址数据为空");
$file_b = fopen("$url_b","r"); if(!$file_b){ die("采集此页失败!");
}
$contents_b = stream_get_contents($file_b);
fclose($file_b);
preg_match_all("/apiItemDesc\":\"(.*?)\"/i", $contents_b, $matches);
$pipei_b = trim($matches[1][0]);
if($pipei_b =='') die("商品描述地址为空"); $handel=fopen("$pipei_b","r");
if(!$handel){ die("采集此页失败!");
}
$contents_a = stream_get_contents($handel);
preg_match_all("/var desc=\'(.*?)\'/i", $contents_a, $matches);
$pipei_a = $matches[1][0];
echo $pipei_a;
?>
$url_b='http://item.taobao.com/auction/item_detail-0db1-0f0c97e6d4b30c7218708c9c6d2ced23.jhtml';
if ($url_b =='') die("地址数据为空");
$file_b = fopen("$url_b","r"); if(!$file_b){ die("采集此页失败!");
}
$contents_b = stream_get_contents($file_b);
fclose($file_b);
preg_match_all("/apiItemDesc\":\"(.*?)\"/i", $contents_b, $matches);
$pipei_b = trim($matches[1][0]);
if($pipei_b =='') die("商品描述地址为空"); $handel=fopen("$pipei_b","r");
if(!$handel){ die("采集此页失败!");
}
$contents_a = stream_get_contents($handel);
preg_match_all("/var desc=\'(.*?)\'/i", $contents_a, $matches);
$pipei_a = $matches[1][0];
echo $pipei_a;
?>
如果fopen不好使建义换socket或是curl方式吧,设好相关头信息,这样会好一些。我用socket的时候基本没遇到取不到的。
我也试验了这个 但是用file的话更会出错 郁闷死
如果怕死锁就加个计数器让他避免.
用 curl 就更好