473,405 Members | 2,415 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,405 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 21322
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.