开发者

Preventing warnings from fsockopen

开发者 https://www.devze.com 2023-01-27 17:46 出处:网络
I use fsockopen() to connect to multiple servers in a loop. However some servers are not valid and I get PHP warnings like the one below:

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

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 开发者_Go百科no data of the requested type was found

Is there a way to prevent these warnings.

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

Or is there another or better solution for this?


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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号