Preventing warnings from fsockopen

≯℡__Kan透↙ 提交于 2019-12-19 16:54:07

问题


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 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?


回答1:


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
}


来源:https://stackoverflow.com/questions/4330494/preventing-warnings-from-fsockopen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!