Jump to content

[SOLVED] file_get_contents 404


Warz

Recommended Posts

Hi,

 

I am been using this command for a while: file_get_contents('http://domain.com');

 

However, recently domain.com changed servers and I'm now recieving following error:

failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/warzfile/public_html/customscripts/file_get_contents_test.php on line 249

 

I do have access to the server I'm trying to "fetch" from. I can also mention that some pages works, while this one don't. It just doesn't make any sense to me  :-[

 

Whats this error? How can I fix this?

 

Thanks!

Link to comment
Share on other sites

This is my code:

$strURL = 'http://dcl.vg.to/fetchme.php?id=11602';
$strContent = file_get_contents($strURL);
echo $strContent;

 

And I get this error

Warning: file_get_contents(http://dcl.vg.to/fetchme.php?id=11602) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/warzfile/public_html/customscripts/file_get_contents_test.php on line 251

 

If you try that url you will see that it works, but not when fetching??

Link to comment
Share on other sites

Well the server your connecting to seams okay, as the connection is valid

Date: Wed, 07 Oct 2009 14:53:12 GMT

Server: Apache/2.2.3 (Red Hat)

X-Powered-By: PHP/5.1.6

Content-Length: 313

Connection: close

Content-Type: text/html; charset=UTF-8

 

200 OK

 

the server your running dvdcoverlinks.com on did it used to work and have you changed anything as i would suggest checking that allow_url_fopen is enabled in PHP.INI configuration file.

allow_url_fopen = On

 

also try another URL see if its any URL or just that one

Link to comment
Share on other sites

Well the server your connecting to seams okay, as the connection is valid

Date: Wed, 07 Oct 2009 14:53:12 GMT

Server: Apache/2.2.3 (Red Hat)

X-Powered-By: PHP/5.1.6

Content-Length: 313

Connection: close

Content-Type: text/html; charset=UTF-8

 

200 OK

 

the server your running dvdcoverlinks.com on did it used to work and have you changed anything as i would suggest checking that allow_url_fopen is enabled in PHP.INI configuration file.

allow_url_fopen = On

 

also try another URL see if its any URL or just that one

Yes allow url fopen is on. Other URLs work. Well, not really all of them...

 

The reason I made this file in the first place was because :

http://dcl.vg.to/details.php?image_id=11602 <--- works, can be fetched

http://dcl.vg.to/details.php?image_id=11605 <--- does NOT work, cannot be fetched

 

When I enter http://dcl.vg.to/details.php?image_id=11605 it fetched http://dcl.vg.to instead!

 

Isn't that strange? Those pages are completely identical (except from a few different values), yet when I try to fetch the 11605 one I'm redirected to main page? Doesn't make any sense at all  :confused:

 

That's why I made this new file, to see if I could figure out what was wrong, and then I'm getting that error...  :confused:

Link to comment
Share on other sites

You might want to check the web server access log and error log on the remote system to see what kind of entries there are that correspond to the http requests being made to it.

 

Are you doing any URL rewriting or checking of thing like HTTP_REFERER on the remote system that would cause the remote server to return a http 404 response code for what you are requesting?

 

Have you recently changed any of your web hosting or moved your domain registration to a new registrar? This almost sounds like a DNS issue where the request is actually going to the wrong server because an old cached DNS entry is being used some of the time or every time.

Link to comment
Share on other sites

This almost sounds like a DNS issue where the request is actually going to the wrong server because an old cached DNS entry is being used some of the time or every time.

I was thinking the same thing!

 

 

just wondering.., try this (may give some insight)

<?php
$strURL = 'http://dcl.vg.to/fetchme.php?id=11602';
$ch = curl_init($strURL);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$strContent= curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
//$strContent = file_get_contents($strURL);
echo $strContent;
echo "<br /><br />DEBUG\n<pre>";
var_dump($info);
echo "</pre>";
?>

Link to comment
Share on other sites

OMG OMG!.... How can I forget something like that  :facewall: :facewall: :facewall: :facewall:

Thank you! yes it must have been DNS issue... I had forgotten to remove the dns records from my old server  ::)

 

Now there is a new error displaying instead:

Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/dvdcover/public_html/customscripts/file_get_contents_test.php on line 4

 

Warning: file_get_contents(http://dcl.vg.to/fetchme.php?id=11602) [function.file-get-contents]: failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/dvdcover/public_html/customscripts/file_get_contents_test.php on line 4

Link to comment
Share on other sites

Here is result from your script:

DEBUG

 

array(20) {

  ["url"]=>

  string(37) "http://dcl.vg.to/fetchme.php?id=11602"

  ["content_type"]=>

  NULL

  ["http_code"]=>

  int(0)

  ["header_size"]=>

  int(0)

  ["request_size"]=>

  int(0)

  ["filetime"]=>

  int(-1)

  ["ssl_verify_result"]=>

  int(0)

  ["redirect_count"]=>

  int(0)

  ["total_time"]=>

  float(0)

  ["namelookup_time"]=>

  float(0)

  ["connect_time"]=>

  float(0)

  ["pretransfer_time"]=>

  float(0)

  ["size_upload"]=>

  float(0)

  ["size_download"]=>

  float(0)

  ["speed_download"]=>

  float(0)

  ["speed_upload"]=>

  float(0)

  ["download_content_length"]=>

  float(-1)

  ["upload_content_length"]=>

  float(-1)

  ["starttransfer_time"]=>

  float(0)

  ["redirect_time"]=>

  float(0)

}

 

Link to comment
Share on other sites

remove the dns records from my old server

It sounds like the domain name record at your domain registrar is still pointing to the name server for the old server as well.

 

With the DNS zone records still present, the IP address was resolving to an actual web server, the old server, and it actually received the http request, but the requested content was not present, giving the 404 response. When you removed the DNS zone records, the IP address is no longer resolving to any web server.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.