By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,683 Members | 1,073 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,683 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.