PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > file_get_contents() or file() not working with URL on same server
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
file_get_contents() or file() not working with URL on same server

Réponse
 
LinkBack Outils de la discussion
Vieux 12/09/2007, 11h17   #1
mmarlow@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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

  Réponse avec citation
Vieux 12/09/2007, 13h19   #2
C.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: file_get_contents() or file() not working with URL on same server

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.

  Réponse avec citation
Vieux 12/09/2007, 13h29   #3
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: file_get_contents() or file() not working with URL on same server

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
==================
  Réponse avec citation
Vieux 12/09/2007, 17h04   #4
mmarlow@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: file_get_contents() or file() not working with URL on same server

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

  Réponse avec citation
Vieux 12/09/2007, 17h26   #5
Paul Herber
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: file_get_contents() or file() not working with URL on same server

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/myfile.php';

Maybe your hosting company can do something similar ...


--
Regards, Paul Herber, Sandrila Ltd. http://www.sandrila.co.uk/
  Réponse avec citation
Vieux 12/09/2007, 18h17   #6
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: file_get_contents() or file() not working with URL on same server

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
==================
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h11.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13376 seconds with 14 queries