Php_network_getaddresses: getaddrinfo failed: name or service unknown

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 unknown

I can’t understand why. Any help would be greatly appreciated.

EDIT: I forgot to mention that I use this to send GET data to $s['url']

+49
php fsockopen
Apr 18 2018-10-18T00
source share
9 answers

If you want to send GET data to a URL, you should use something simple like file_get_contents ();

 $myGetData = "?var1=val1&var2=val2"; file_get_contents($url.$myGetData); 
+19
Apr 18 '10 at 8:16
source share

Unable to open the connection directly on the path on the remote host using fsockopen . The URL www.mydomain.net/1/file.php contains the path when the only valid value for this first parameter is the host, www.mydomain.net .

If you are trying to access a remote URL, file_get_contents () is best. You can provide the full URL of this function, and it will receive content in this place using a regular HTTP request.

If you want to send an HTTP request and ignore the response, you can use fsockopen() and manually send the HTTP request headers, ignoring any response. It might be easier with cURL , although or just the old fopen () , which will open the connection, but will not necessarily read any answer. If you want to do this 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"); 

This leaves any error handling, of course, but it will mean that you are not wasting time reading the answer.

+32
Apr 18 '10 at 8:11
source share

I had a similar problem on my local test server and local test domains, for example: www.testdomain.loc, with the GetImageSize() function;

Solved it by adding the hostname to the hosts file on the local server:

In the / etc / hosts file, I added:

 192.168.1.1 www.testdomain.loc 

Hope this helps someone

+18
Oct 20 '12 at 9:35
source share
 $url = "http:user:pass@//www.example.com/abc.php?var1=def"; $url = urlencode($url); $contents = file_get_contents(urldecode($url)); echo $contents; 
+3
Mar 24 '13 at 15:07
source share

You are trying to open a socket in a file on a remote host, which is incorrect. You can make a socket connection (TCP / UDP) with the port number on the remote host. so your code should look like this:

 fsockopen('www.mysite.com', 80); 

If you are trying to create a file pointer resource in a remote file, you can use the fopen () function. but for this you also need to specify the application protocol.

PHP provides default stream fairings for a URL file. based on the URL scheme, the corresponding stream wrapper will be called internally. The URL you are trying to open does not have a valid scheme for this solution. make sure it has a scheme like "http: //" or "ftp: //".

so the code will look like this:

 $fp = fopen('http://www.mysite.com/path/file.txt'); 

Also, I don’t think that the HTTP stream fairing (which handles actions in file resources by URL using the http scheme) supports data writing. you can use fread () to read the contents of the url via HTTP, but I'm not sure about the spelling.

EDIT: from the comments and other answers, I realized that you would want to send an HTTP request to the specified URL. The methods described in this answer are for when you want to receive data from a remote URL. if you want to send data, you can use http_request () for this.

+1
Apr 18 2018-10-18T00:
source share

I was getting the same fsocket () error and I just updated the host files

  • I registered through SSH on a CentOS server. Username and password type
  • cd / etc /
  • ls // "view only"
  • vi hosts // "edit host file"
  • I & nbsp // "to put the file in insert mode"
  • 95.183.24.10 [mail_server_name] in my case ("mail.kingologic.com")
  • Press the ESC key
  • click zz

Hope it solves your problem.

for any further request please email me at http://kingologic.com

+1
Feb 26 '16 at 15:03
source share

In my case, this error is caused by the incorrect configuration of /etc/nsswitch.conf on debian.

I replaced the string

 hosts: files myhostname mdns4_minimal [NOTFOUND=return] dns 

from

 hosts: files dns 

and everything works right now.

+1
Nov 10 '16 at 7:34
source share

Try setting the ENV PATH . Add the PHP path to the ENV PATH.

For this extension to work, there are DLL files that must be available for the PATH system for Windows. For information on how to do this, see the "Frequently Asked Questions" section entitled "How to add the PHP directory to PATH on Windows." Although copying DLL files from the PHP folder to the Windows system directory also works (since the system directory is by default on the PATH system), this is not recommended. The following files in PATH are required for this extension: libeay32.dll

http://php.net/manual/en/openssl.installation.php

0
Jun 06 '15 at 6:40
source share

in simple words, your site is blocked for access to the network. maybe you automated some script, and this led to the blocking of your entire site. the best way to resolve this is to contact this site and talk about your problem. if the problem is genuine, they may consider unlocking

0
Jul 23 '17 at 13:18
source share



All Articles