0

So I'm trying to read from a remote file (which used to work) and it stopped working after transferring servers. The code looks like this:

$import_handle = fopen("http://www.example.com/path/", "r");

This is the error I'm getting (from error_get_last()):

fopen(http://www.example.com/path/): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known

I can confirm that example.com/path is working. What's the cause of the error and what am I missing?

Thanks for any help.

tg13
  • 35
  • 3
  • 11
  • Have you tried the suggestions given [here](https://stackoverflow.com/questions/20064372/file-get-contents-php-network-getaddresses-getaddrinfo-failed-name-or-servi) and [here](https://stackoverflow.com/questions/6897506/fopen-fails-with-getaddrinfo-failed)? Have you considered using [file_get_contents()](http://php.net/manual/en/function.file-get-contents.php)? (will likely have the same issue, but may be better-suited to what you're trying to do) – Patrick Q Aug 24 '17 at 17:33
  • Yes, I stumbled across them - the thing is, it used to work before and only the remote site changed servers, not the one I'm running the script off from. I use fopen() since I need to do fgets() as the remote script being opened is a generated CSV file. And I don't have access to Apache on both servers, only FTP. – tg13 Aug 24 '17 at 17:53
  • Update: file_get_contents() returns the same error. – tg13 Aug 24 '17 at 20:13

2 Answers2

0

I had a similar problem once, it was mainly because my php.ini settings was
allow_url_fopen=Off
changing that to
allow_url_fopen=On
Solved the issue, remember to restart your Apache Server after changing it.

Mo-
  • 155
  • 15
-2

I just found the solution!

I changed

$import_handle = fopen("http://www.example.com/path/", "r");

to

$import_handle = fopen("path/", "r");