我使用此方法从网站的html中提取数据。但有时它会卡住。如何防止它超时?它应该简单地说,而不是给出一些奇怪的错误。现在无法获取结果
$html = file_get_contents('https://homeshopping.pk/search.php?category%5B%5D=&search_query='.$homeshoppingSearch);
$pk_doc = new DOMDocument();
libxml_use_internal_errors(TRUE);
if(!empty($html)){
$pk_doc->loadHTML($html);
libxml_clear_errors();
$pk_xpath = new DOMXPath($pk_doc);
/
//Homeshopping
$pk_row = $pk_xpath->query('//a[@class=""]');
$pk_row2 = $pk_xpath->query('//a[@class="price"]');
$pk_row3 = $pk_xpath->query('(//a[@class="price"])//@href');
//HomeShopping
if($pk_row->length > 0){
$rowarray = array();
foreach($pk_row as $row){
$rowarray[]= $row->nodeValue;
// echo $row->nodeValue . "<br/>";
}
}
if($pk_row2->length > 0){
$row2array = array();
foreach($pk_row2 as $row2){
$row2array[]=$row2->nodeValue;
// echo $row2->nodeValue . "<br/>";
}
}
if($pk_row3->length > 0){
$row3array = array();
foreach($pk_row3 as $row3){
$row3array[]=$row3->nodeValue;
//echo $row3->nodeValue . "<br/>";
}
}
}