Home > Backend Development > PHP Tutorial > PHP使用fopen的时候能否捕获HTTP流错误

PHP使用fopen的时候能否捕获HTTP流错误

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:50:04
Original
1069 people have browsed it

当我打开一个不存在的页面的时候,比如

<code>fopen('http://bucunzai.com/none.html', 'r');
</code>
Copy after login
Copy after login

会报错,提示:

failed to open stream: HTTP request failed

请问能否捕获这个信息而不是报错呢?

回复内容:

当我打开一个不存在的页面的时候,比如

<code>fopen('http://bucunzai.com/none.html', 'r');
</code>
Copy after login
Copy after login

会报错,提示:

failed to open stream: HTTP request failed

请问能否捕获这个信息而不是报错呢?

试过哦,可以获得错误信息,但是不可以阻止报错,另外我也知道可以用CURL以及@避免,不过我现在需要用到fopen,也希望尽量不使用"@",不知道有没有好的办法

系统函数(fopen)本身设定为报出错误信息,无法更改现实。除非你重新编译php源码。 或者你就老老实实用curl

try {
fopen('http://bucunzai.com/none.html', 'r');
}
catch (Exception $e) {   
print $e->getMessage(); 
}
Copy after login

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template