Php 如何在简单HTML Dom解析器中处理http错误

Php 如何在简单HTML Dom解析器中处理http错误,php,html,dom,simple-html-dom,Php,Html,Dom,Simple Html Dom,所以我有这个 $r1pro = file_get_html('http://www.example.com/forums-profile.php?user_id='.$uid); $uname = $r1pro->find('span.username', 0); 它工作得很好,但站点设计得不是很好,如果您未登录,某些请求会返回500错误,其输出类似以下内容: Warning: file_get_contents(http://www.example.com/forums-profile

所以我有这个

$r1pro = file_get_html('http://www.example.com/forums-profile.php?user_id='.$uid);
$uname = $r1pro->find('span.username', 0);
它工作得很好,但站点设计得不是很好,如果您未登录,某些请求会返回500错误,其输出类似以下内容:

Warning: file_get_contents(http://www.example.com/forums-profile.php?user_id=12345678): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in /home/mysite/public_html/su3/htmldom.php on line 76
Fatal error: Call to a member function find() on boolean in /home/mysite/public_html/su3/index.php on line 61

我在simplehtmldom中搜索了错误处理方法,但没有找到任何结果。有没有办法捕捉http错误并运行不同的代码呢?

没关系,我现在觉得自己很愚蠢。我所要做的就是

if($r1pro){
<--do normal stuff if no error-->
}else{
<--do stuff in case of error-->
}
if($r1pro){
}否则{
}