Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing warnings from fsockopen

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?

like image 824
PeeHaa Avatar asked Dec 02 '10 00:12

PeeHaa


1 Answers

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
}
like image 178
Byron Whitlock Avatar answered Nov 02 '22 21:11

Byron Whitlock