I use SIMPLE HTML DOM. Some pages take a long time -> then Warning (HTTP request failed) -> find() doesn`t work! FATAL ERROR! How to go to the next page?
$items = [...];
foreach ($item as $link) {
$html = new simple_html_dom();
$html -> load_file($link);
if (WHAT SHOULD I WRITE HERE TO START PARSING WHEN $html is OK?) {
some parsing
}
}
答案 0 :(得分:0)
如果行$html -> load_file($link);
是导致页面超时的行,则您无法在下一行中执行任何操作。
也许可以考虑在set_time_limit
循环之前增加set_time_limit(0)
或停用foreach
。
$items = [...];
set_time_limit(300);
foreach ($item as $link) {
$html = new simple_html_dom();
$html -> load_file($link);
if (WHAT SHOULD I WRITE HERE TO START PARSING WHEN $html is OK?) {
some parsing
}
}
您应该阅读set_time_limit documentation和max execution time documentation。
请注意,在网络环境中增加此值可能不是一个好主意。另外,请注意,根据PHP文档,apache似乎在300秒(5分钟)内超时。