file_get_contents() or file() not working with URL on same server
file_get_contents() or file() not working with URL on same server
am 12.09.2007 12:17:10 von mmarlow
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
Re: file_get_contents() or file() not working with URL on same server
am 12.09.2007 14:19:52 von colin.mckinnon
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.
Re: file_get_contents() or file() not working with URL on same server
am 12.09.2007 14:29:46 von Jerry Stuckle
mmarlow@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.
jstucklex@attglobal.net
==================
Re: file_get_contents() or file() not working with URL on same server
am 12.09.2007 18:04:05 von mmarlow
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
Re: file_get_contents() or file() not working with URL on same server
am 12.09.2007 18:26:51 von Paul Herber
On Wed, 12 Sep 2007 10:17:10 -0000, mmarlow@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/myf ile.php';
Maybe your hosting company can do something similar ...
--
Regards, Paul Herber, Sandrila Ltd. http://www.sandrila.co.uk/
Re: file_get_contents() or file() not working with URL on same server
am 12.09.2007 19:17:30 von Jerry Stuckle
mmarlow@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.
jstucklex@attglobal.net
==================