我使用fsockopen()连接到循环中的多个服务器.
但是有些服务器无效,我收到如下所示的PHP警告:
Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: The requested name is valid, but no data of the requested type was found
Run Code Online (Sandbox Code Playgroud)
有没有办法防止这些警告.
就像在尝试fsockopen之前检查服务器是否良好一样?
或者还有其他更好的解决方案吗?
我成功地获取网站
file_get_contents("http://www.site.com");
Run Code Online (Sandbox Code Playgroud)
但是,如果网址不存在或无法访问,我会收到
Warning: file_get_contents(http://www.site.com) [function.file-get-contents]:
failed to open stream: operation failed in /home/track/public_html/site.php
on line 773
Run Code Online (Sandbox Code Playgroud)
是否可以echo "Site not reachable";代替错误?
我有一个这样的脚本:
<html>
<body>
<?php
require("wrongFile.php");
echo "Hello World!";
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
现在如果错误文件不存在,则会报告以下两个错误:
警告:require(wrongFile.php)[function.require]:无法打开流:第5行的C:\ home\website\test.php中没有这样的文件或目录
致命错误:require()[function.require]:在第5行的C:\ home\website\test.php中打开所需的'wrongFile.php'(include_path ='.; C:\ php5\pear')失败
我知道如果不存在require()函数中的文件,则显示致命错误导致脚本执行停止但不明白什么是第一个错误
使用include()函数时的第一个错误显示
我知道通常可以使用error_reporting(0)或'@'来抑制php错误.我有很多的SQL查询我的工作的某部分被解雇了,我想知道,它增加的error_reporting(0)抑制来自MySQL的查询引起的误差的出现?
我在线阅读不同的答案.有些人表示会有所帮助,而有些人则表示不会那样工作.