3

I'm facing a strange problem with PHP CLI.

PHP runs perfectly fine when accessing files through the web browser. I can run CURL scripts, connect to databases and perform any kind of connection available on PHP, either locally or to external addresses.

But if I run the same script on CLI, I always get the following error:

Warning Error: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Host desconocido. in ...

This is a global problem, and it's not related to my scripts, because if I run, for example, the installation for composer, I get the same error while trying to install.

I tried reinstalling WAMP, going back to the default PHP.ini and enabling IPv6. I compared the ini values on CLI and on normal mode (through ini_get_all()) and there were no differences, besides the normal ones.

I'm running WAMP latest version, on Windows 8 x64.

Andres
  • 249
  • 3
  • 16
  • Have you checked this ? http://stackoverflow.com/questions/6275535/php-error-php-network-getaddresses-getaddrinfo-failed-while-getting-informat – Rabea Nov 30 '15 at 19:39
  • Use `ping
    ` and you'll see that the host is most likely not up or DNS can't resolve it. To test with the raw MySQL command, just use `mysql -h mydomain.com -u -p`
    – h2ooooooo Nov 30 '15 at 19:46
  • @MarcB I don't think its a DNS problem. PHP and browser works perfectly as intended. I can even ping any url in CMD. This problem only happens on PHP CLI. PHP through web browser works perfectly. – Andres Nov 30 '15 at 19:47
  • @Andres If you look at your full error message, can you verify that the host `desconocido` (without any extension) is your actual domain? – h2ooooooo Nov 30 '15 at 19:47
  • @Andres: well, if dns was working, you wouldn't getting a getaddrinfo fail. – Marc B Nov 30 '15 at 19:47
  • @h2ooooooo "Host desconocido" its actually "host unknown" in spanish. It will fail either connecting to localhost, 127.0.0.1 or an external address (like google.com) – Andres Nov 30 '15 at 19:49
  • @MarcB mmmm, what could be the cause to be only triggered on CLI then? – Andres Nov 30 '15 at 19:49
  • @Andres It's a shot in the dark, but are you sure that the code executed is the same? I don't know how you're referencing your host, but a lot of frameworks use a different configuration file for CLI scripts. Could you show us your PHP code? Have you tried using `var_dump( $host )` before the request to verify? – h2ooooooo Nov 30 '15 at 19:51
  • @h2ooooooo Problem is that this is triggered generally. Doesn't matter what I'm doing. Right now what's failing is a CakePHP PDO connection, but I get the same error when installing composer, for example. The issue is that somehow PHP CLI can't resolve any address, no matter if it is a CURL script, a PDO connect or a simple ping. – Andres Nov 30 '15 at 19:55
  • @Andres Do you have some sort of firewall blocking or antivirus the PHP CLI program from accessing the web, but allows other programs to do so? Windows firewall might very well be the culprit here. Try to add `php.exe` to your exceptions. – h2ooooooo Nov 30 '15 at 19:58
  • Make sure php.exe is not forbidden to use the network at the OS firewall level. – Calimero Nov 30 '15 at 19:58
  • @h2ooooooo Windows Firewall is completely disabled – Andres Nov 30 '15 at 20:00
  • @Calimero Windows Firewall is completely disabled – Andres Nov 30 '15 at 20:00
  • @Andres, any chance you have another software on that computer acting as such ? – Calimero Nov 30 '15 at 20:04
  • @Calimero Nothing, not even on a router level. Also, AFAIK, no other software on my computer suffers from this. No connectivity problems without any other software. – Andres Nov 30 '15 at 20:05
  • @Andres Could you verify that the config file that your CLI PHP uses is more or less identical to the one apache uses? There might be sublte differences, although with a default wamp installation it should work fine. Have you tried running your command prompt as an administrator? – h2ooooooo Nov 30 '15 at 20:15
  • @h2ooooooo both files are identical. The only difference is the xdebug config and the POST_MAX_SIZE value. – Andres Nov 30 '15 at 20:26
  • It's another shot in the dark but have you tried downloading a new fresh clean php cli build from the php website and running that instead? – h2ooooooo Nov 30 '15 at 20:44

0 Answers0