Here is a snippet of my code
$fp = fsockopen($s['url'], 80, $errno, $errstr, 5); if($fp){ fwrite($fp, $out); fclose($fp);
When I run it, it outputs:
unable to connect to www.mydomain.net/1/file.php:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known
I'm using this to submit GET data to the $s['url']
I can't figure out why. Any help would be greatly appreciated.
Error : Failed to connect to server: php_network_getaddresses: getaddrinfo failed. This error can occur due to two reasons. One, there might me an issue with your DNS settings and second, PHP may not be able to get the network addresses for a given host/domain name.
That usually means your DNS resolution is not working correctly. PHP cannot get the ip-address for hostnames used in the Memcache functions. Your options. Check/fix that DNS-lookups can be done correctly. Change your code to use ip-addresses instead of hostnames.
You cannot open a connection directly to a path on a remote host using fsockopen
. The url www.mydomain.net/1/file.php
contains a path, when the only valid value for that first parameter is the host, www.mydomain.net
.
If you are trying to access a remote URL, then file_get_contents() is your best bet. You can provide a full URL to that function, and it will fetch the content at that location using a normal HTTP request.
If you only want to send an HTTP request and ignore the response, you could use fsockopen()
and manually send the HTTP request headers, ignoring any response. It might be easier with cURL though, or just plain old fopen(), which will open the connection but not necessarily read any response. If you wanted to do it with fsockopen()
, it might look something like this:
$fp = fsockopen("www.mydomain.net", 80, $errno, $errstr, 30); fputs($fp, "GET /1/file.php HTTP/1.1\n"); fputs($fp, "Host: www.mydomain.net\n"); fputs($fp, "Connection: close\n\n");
That leaves any error handling up to you of course, but it would mean that you wouldn't waste time reading the response.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With