Search code examples
phpnetwork-programmingwindows-7dnsfsockopen

How to get custom domain names to work with "php_network_getaddresses"


My domain is set in the windows "hosts" file and it is named like "my.site". I'm using it for development.

But this doesn't seem to work with the fsockopen() open function. I get "php_network_getaddresses: getaddrinfo failed: Name or service not known".

Is it possible to make it work?


Solution

  • This completely works for me:

    // inside hosts file:
    // 10.128.0.23 test.domain.example
    
    $socket = fsockopen('test.domain.example', 80);
    fclose($socket);
    

    I can ping that domain name and get a valid answer, and it runs a web server on port 80.

    I read from your comment that your PHP is inside a virtual machine - then you should try if the ping does work there also, and if not: add the domain name to your hosts file as well. Virtual machines do not necessarily inherit the name resolving capabilities of their hosts.