Warz Posted October 7, 2009 Share Posted October 7, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/ Share on other sites More sharing options...
GingerRobot Posted October 7, 2009 Share Posted October 7, 2009 Umm, maybe they deleted that page? Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932328 Share on other sites More sharing options...
Warz Posted October 7, 2009 Author Share Posted October 7, 2009 No, I am the owner of both servers and I can access that page with no problem by entering it in firefox.... Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932331 Share on other sites More sharing options...
MadTechie Posted October 7, 2009 Share Posted October 7, 2009 Need more info.. ie the url your trying, best guess is your URL is incorrect, (check for spaces) Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932334 Share on other sites More sharing options...
Warz Posted October 7, 2009 Author Share Posted October 7, 2009 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?? Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932336 Share on other sites More sharing options...
MadTechie Posted October 7, 2009 Share Posted October 7, 2009 returns this via PHP (here) Connected successfully <html><head><title>Monsters vs Aliens</title></head><body> <table> <tr><td>Thumb:</td><td>http://dcl.vg.to/data/thumbnails/61/Monsters_vs_Aliens.jpg</td></tr> <tr><td>Pixel:</td><td>3240x2175</td></tr> <tr><td>Size:</td><td>5.23 MB</td></tr> </table> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932340 Share on other sites More sharing options...
Warz Posted October 7, 2009 Author Share Posted October 7, 2009 That's strange... any idea why it doesn't work for me? Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932341 Share on other sites More sharing options...
Jahren Posted October 7, 2009 Share Posted October 7, 2009 what version of IE? any manuipulation with the url? not encoded special chars? Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932351 Share on other sites More sharing options...
Warz Posted October 7, 2009 Author Share Posted October 7, 2009 What does this have to do with IE? IE as in Internet Explorer? or...? Since it's working for MadTechie I assume it must be some sort of server error? Also donno what you mean by manuipulation of url... I'm just using the url http://dcl.vg.to/fetchme.php?id=11602 Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932358 Share on other sites More sharing options...
Jahren Posted October 7, 2009 Share Posted October 7, 2009 Well, because a browser interpretation of code and url interpretation can differ alot from a version to an other. is it external hosting? (I believe so but still asking) Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932360 Share on other sites More sharing options...
Warz Posted October 7, 2009 Author Share Posted October 7, 2009 Yes, it's two completely different servers. The url is hardcoded so it can't be changing based on browser. You can see http://dvdcoverlinks.com/customscripts/file_get_contents_test.php this is where the script is runned... Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932373 Share on other sites More sharing options...
MadTechie Posted October 7, 2009 Share Posted October 7, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932383 Share on other sites More sharing options...
Warz Posted October 7, 2009 Author Share Posted October 7, 2009 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 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... Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932391 Share on other sites More sharing options...
PFMaBiSmAd Posted October 7, 2009 Share Posted October 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932394 Share on other sites More sharing options...
MadTechie Posted October 7, 2009 Share Posted October 7, 2009 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932401 Share on other sites More sharing options...
Warz Posted October 7, 2009 Author Share Posted October 7, 2009 OMG OMG!.... How can I forget something like that :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 Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932405 Share on other sites More sharing options...
Warz Posted October 7, 2009 Author Share Posted October 7, 2009 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) } Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932406 Share on other sites More sharing options...
MadTechie Posted October 7, 2009 Share Posted October 7, 2009 Basic result is server host not found.. try pinging server from PHP server (check IP returned if any), check 'A Record's / Name server Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932412 Share on other sites More sharing options...
PFMaBiSmAd Posted October 7, 2009 Share Posted October 7, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932425 Share on other sites More sharing options...
MadTechie Posted October 7, 2009 Share Posted October 7, 2009 But if you look at the curl http_code is 0 and NOT 404 as expected so I say domain not found at all! Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932428 Share on other sites More sharing options...
Warz Posted October 7, 2009 Author Share Posted October 7, 2009 Thanks a lot guys! I had to delete even som more records, like the nameservers. It seems to be working fine now :happy-04: Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932438 Share on other sites More sharing options...
MadTechie Posted October 7, 2009 Share Posted October 7, 2009 Just one thing remaining then.. clicking of the topic solved button (bottom left) Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932442 Share on other sites More sharing options...
Warz Posted October 7, 2009 Author Share Posted October 7, 2009 Check Quote Link to comment https://forums.phpfreaks.com/topic/176828-solved-file_get_contents-404/#findComment-932445 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.