防止来自 fsockopen 的警告 [英] Preventing warnings from fsockopen

查看:45
本文介绍了防止来自 fsockopen 的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 fsockopen() 循环连接到多个服务器.

I use fsockopen() to connect to multiple servers in a loop.

但是有些服务器无效,我收到如下所示的 PHP 警告:

However some servers are not valid and I get PHP warnings like the one below:

Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: The requested name is valid, but no data of the requested type was found

有没有办法防止这些警告.

Is there a way to prevent these warnings.

喜欢在尝试 fsockopen 之前检查服务器是否良好?

Like checking whether the server is good before trying to fsockopen it?

或者有其他更好的解决方案吗?

Or is there another or better solution for this?

推荐答案

使用 错误控制运算符并检查 fsockopen() 的结果以验证您的连接是否有效.

Use the error control operator and check the results of fsockopen() to verfiy you have a valid connection.

$rc = @fsockopen(...);
if (is_resource($rc))
{
   // do work
}

这篇关于防止来自 fsockopen 的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆