0
votes

I'm using a simple fopen statement to read a text file, but I get:

fopen(http://www.domain.nl/cees.txt): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

If I call http://www.domain.nl/cees.txt in my browser, the content displays without any problem, so the file exists (right?)....

I also tried cUrl, but it also returns a 404.

If I try my php-script on another host, it works just fine, so I figured I'd compare the settings for both hosts, but they are identical with allow_url_fopen On in both cases.

There's no htaccess and permissions on rootfolder are 755.

I'm pulling my hair out over this. Anyone has any suggestion?

2
Have you tried using the absolute path? - Naruto
a) domain.nl has anti-scraping protection being triggered by whatever host is getting the 404. b) proxy/gateway in between is filtering. so...do you have access to domain.nl's logs to see what gets logged for both the good and bad requests? - Marc B
try using curl and passing an user-agent - Alex Andrei
Probably the USER_AGENT is not set and eventually an error is generated as the systems (correctly?) guessed that it has not been called via a browser/human. - Jan
Both hosts are on the same VPS (mine!). I have tried cUrl (with and without useragent) and file_get_content, but they all give a 404. I've put the example online: aangenaam.nl/fopen.php - Cees Rijken

2 Answers

0
votes

Here is my try:

The server that can't reach the file is behind a proxy. You may as well be behind the proxy and your browser is configure to go through. But not your php script.

Check your browser's config if it use a proxy. If so, then fopen has to use it too:

$opts= array(
                 'http' => array( 
                 'proxy' => 'tcp://proxyip:8080', 
                 'header' => array( 
                                     "Proxy-Authorization: Basic $auth" 
                                  ) 
                ) 
); 
$context = stream_context_create($opts);
$file = fopen($url, 'r', false, $context)
0
votes

In a moment of clarity I decided to check the httpd.conf and found that the VirtualHost-line for the specified domain contained the IP4-address, but NOT the IP6-address.

I added the IP6-address, restarted Apache and I am happy little bunny!!!

Hope this helps someone else...