473,324 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

file_get_contents() or file() not working with URL on same server

Hi all,
I'm trying to get the contents of a file from a URL using
file_get_contents() or file(). It doesn't work, it eventually just
times out. It used to display a 'failed to open file' message but now
returns nothing at all.

- it works with any site that's not on our server, eg: google.com
- allow_url_fopen is ON (proven with the above test)
- we have two load balanced servers with identical settings, could
this be an issue?

Thanks,
Mat Marlow

Sep 12 '07 #1
5 21312
C.
On 12 Sep, 11:17, mmar...@gmail.com wrote:
Hi all,
I'm trying to get the contents of a file from a URL using
file_get_contents() or file(). It doesn't work, it eventually just
times out. It used to display a 'failed to open file' message but now
returns nothing at all.

- it works with any site that's not on our server, eg: google.com
- allow_url_fopen is ON (proven with the above test)
- we have two load balanced servers with identical settings, could
this be an issue?
Its an issue if you want to fetch local files this way.

Probably not a PHP isue though - more likely to be name resolution or
firewall settings. Try using wget from the command line on the server
to do the same thing and/or sniffing an attempt to connect.

C.

Sep 12 '07 #2
mm*****@gmail.com wrote:
Hi all,
I'm trying to get the contents of a file from a URL using
file_get_contents() or file(). It doesn't work, it eventually just
times out. It used to display a 'failed to open file' message but now
returns nothing at all.

- it works with any site that's not on our server, eg: google.com
- allow_url_fopen is ON (proven with the above test)
- we have two load balanced servers with identical settings, could
this be an issue?

Thanks,
Mat Marlow
Mat,

First of all, if it used to display a message but doesn't now, something
has changed. Check phpinfo() to ensure there wasn't an inadvertent
change, i.e. due to an upgrade of PHP, someone else changing the php.ini
file, etc.

If phpinfo() looks good, go to a command line and try to access the page
with telnet, i.e.

telnet example.com 80
GET /
(press enter again)

See if you get the page back. If so, the problem is in your PHP code.

If you don't, the problem is not in your php code, but your site or the
remote. It could be, for instance, the site has changed to require an
HTTP version, i.e.

GET / HTTP/1.1

And I'm not sure file() or file_get_contents() will send such a header.
I never traced it. But if that is the case, you may have to use CURL
to get the page.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 12 '07 #3
Thanks for your responses folks.

- I've tried CURL, with the same result.
- I have also SUCCESSFULLY tested this using the same files from our
local server, and it returns the contents of the page no problem

With that in mind, I think the firewall idea might be something to
look into. It does seem to be some problem with our server accessing
itself so I guess we could start there unless anyone has any more
bright ideas?

thanks again,
Mat

Sep 12 '07 #4
On Wed, 12 Sep 2007 10:17:10 -0000, mm*****@gmail.com wrote:
>Hi all,
I'm trying to get the contents of a file from a URL using
file_get_contents() or file(). It doesn't work, it eventually just
times out. It used to display a 'failed to open file' message but now
returns nothing at all.

- it works with any site that's not on our server, eg: google.com
- allow_url_fopen is ON (proven with the above test)
- we have two load balanced servers with identical settings, could
this be an issue?
I had a similar problem when a hosting company started using a load
balancer. I wanted to share a file from a subdomain amongst various
other subdomains (it was actually a file containing some exchange rate
data that I wanted to be common between various subdomains).

The hosting company's support people gave me their solution:

include
'http://www.sub.mydomain.dom.web-internal.hostdomain.net/myfile.php';

Maybe your hosting company can do something similar ...
--
Regards, Paul Herber, Sandrila Ltd. http://www.sandrila.co.uk/
Sep 12 '07 #5
mm*****@gmail.com wrote:
Thanks for your responses folks.

- I've tried CURL, with the same result.
- I have also SUCCESSFULLY tested this using the same files from our
local server, and it returns the contents of the page no problem

With that in mind, I think the firewall idea might be something to
look into. It does seem to be some problem with our server accessing
itself so I guess we could start there unless anyone has any more
bright ideas?

thanks again,
Mat
If it's working on another server, then the code itself is OK. So it's
got to be something on the server itself.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 12 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rob | last post by:
for some reason i keep getting : Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /home/rob/www/php/filegetcontents2.php on...
3
by: Csaba Gabor | last post by:
I've got a section of code that takes a user supplied $url and essentially does: function redirectRequest($url) { $resultRemote = @file_get_contents($url); return $resultRemote; } Is there a...
0
by: Eduardo | last post by:
Hi people I'm working with ajax in PHP 5 posting JSON thru raw_post_data. The data get with file_get_contents function. That's all works until config the .haccess file. I make that to all...
1
by: jjainschigg | last post by:
I'm running PHP 5 on a shared VPS. I have a couple little apps that are using file_get_contents() and readfile() for various kinds of (what should be) low-overhead, fast outbound accesses ... that...
5
by: howa | last post by:
are there any advantage in replacing all fread() operations with file_get_contents() ? i.e. file_get_contents("/usr/local/something.txt") VS $filename = "/usr/local/something.txt";
4
by: Aetherweb | last post by:
This is probably really obvious, sorry, been a long day... I'm wanting to create a PHP file which is a template for an email, and read the file into a string, ready to send out using my email...
1
by: mouseit | last post by:
This may be a very easy question, and I may need to supply more information, but basically trying to read a file at a URL with file_get_contents() returns the error message: : failed to open...
3
by: BPG | last post by:
Hi There, I'm running into a little problem using "file_get_contents". When i try to open a page just using my browser i can see the consents of the page, however, when i try to open this same...
0
by: pac1250 | last post by:
Hi, I am searching how to solve a problem and I dont find it :( I want to access a page from a script behind a proxy : (my script) <-(a proxy with authentification) <-(https serveur with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.