473,396 Members | 1,942 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,396 software developers and data experts.

Why get_file_contents not working?

17
Hi, All. I am new to PHP. Though I dug through this forum to try to find an answer to get_file_contents function, I failed. Please help with the below problem.

I am testing building a page by using google maps api to retrieve data from a news site and plotting markers on google map. Because the news is constantly updated, i used script proxy on server side to get remote file, the user's brower will dynamically parse the data and load the result. The link is at:
<Link removed>
The problem is that when I use get_file_contents(remote target file), there is warning "Failed to open stream..." I want a reliable way to get the file, some identified it as OFF in PHP ini fopen, it seems not that simple. And I need a method to detect if ISP has disabled fopen function.

Or you may suggest other ways to workaround this and get the file each time the browser loads the map.

Thank you very much in advance.
Your any help will be appreciated.
Sep 28 '07 #1
11 13770
Atli
5,058 Expert 4TB
Hi. Welcome to The Scripts!

I removed the link from your post. All links to commercial webs are strictly forbidden on the technical forums. Please read the Posting Guidelines for more info on our posting policies.

Ok, getting to the problem.
Could you post the error messages you are getting?
And maybe the code that is generating them?

Also, keep in mind that most of the file system functions require the 'allow_url_fopen' directive in your php.ini to be enabled in order to open URLs.

To test this, simply execute this code. If it prints 0 it is disabled. 1 means it is enabled.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo ini_get("allow_url_fopen");
  3. ?>
  4.  
Sep 28 '07 #2
1965
17
Thank you very much.Ati.

error warning is
Warning: file_get_contents(remote url): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in D:\wwwroot\guoshesen\wwwroot\map\rssxml.php on line 3

As that remote url is an xml file, I can smoothly open it in my IE but not through php proxy script..
Sep 28 '07 #3
pbmods
5,821 Expert 4TB
Heya, 1965.

You're getting a 404, which means that the URL that you're requesting doesn't exist.

Try echoing your URL to make sure you're passing to file_get_contents() what you think you're passing to file_get_contents().
Sep 28 '07 #4
1965
17
Thank you Pbmods and Atli, but the url does really exist. Because every day I am using the url to download the xml, though manually. that url is used to retrieve data

http://ws.geonames.org/rssToGeoRSS?feedUrl=http://hosted.ap.org/lineups/WORLDHEADS-rss_2.0.xml?SITE=RANDOM&SECTION=HOME

. So please let know any clues to solutions.
Sep 28 '07 #5
pbmods
5,821 Expert 4TB
Heya, 1965.

What does your file_get_contents() call look like?
Sep 28 '07 #6
1965
17
one line
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $file = file_get_contents ('http://ws.geonames.org/rssToGeoRSS?feedUrl=http://hosted.ap.org/lineups/WORLDHEADS-rss_2.0.xml?SITE=RANDOM&SECTION=HOME'); 
  3. Echo $file;
  4. ?>
Sep 28 '07 #7
pbmods
5,821 Expert 4TB
Heya, 1965.

Please use CODE tags when posting source code:

[CODE=php]
PHP code goes here.
[/CODE]
Sep 28 '07 #8
pbmods
5,821 Expert 4TB
Try this:
Expand|Select|Wrap|Line Numbers
  1. $file = file_get_contents( 'http://ws.geonames.org/rssToGeoRSS?feedUrl=' . urlencode('http://hosted.ap.org/lineups/WORLDHEADS-rss_2.0.xml?SITE=RANDOM&SECTION=HOME') );
  2.  
Or for maximum efficiency:
Expand|Select|Wrap|Line Numbers
  1. $file = file_get_contents( 'http://ws.geonames.org/rssToGeoRSS?feedUrl=http%3A%2F%2Fhosted.ap.org%2Flineups%2FWORLDHEADS-rss_2.0.xml%3FSITE%3DRANDOM%26SECTION%3DHOME');
  2.  
Sep 28 '07 #9
1965
17
Thank you very much. Pbmods. I have read your code, I am away from my desk for a while, I will let you know my test result after a while. Thank you again.
Sep 28 '07 #10
1965
17
Dear Pbmods:

I just tried twice your two codes. It still does not work. Below are errors. Why?

In IE
Warning: file_get_contents(http://ws.geonames.org/rssToGeoRSS?feedUrl=http%3A%2F%2Fhosted.ap.org%2Fl ineups%2FWORLDHEADS-rss_2.0.xml%3FSITE%3DRANDOM%26SECTION%3DHOME): failed to open stream: HTTP request failed! in D:\wwwroot\guoshesen\wwwroot\map\rssxml.php on line 3

In IE
Warning: file_get_contents(http://ws.geonames.org/rssToGeoRSS?feedUrl=http%3A%2F%2Fhosted.ap.org%2Fl ineups%2FWORLDHEADS-rss_2.0.xml%3FSITE%3DRANDOM%26SECTION%3DHOME): failed to open stream: HTTP request failed! in D:\wwwroot\guoshesen\wwwroot\map\rssxml.php on line 3

In Opera:
Fatal error: Maximum execution time of 30 seconds exceeded in D:\wwwroot\guoshesen\wwwroot\map\rssxml.php on line 3
Sep 28 '07 #11
mwasif
802 Expert 512MB
one line
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $file = file_get_contents ('http://ws.geonames.org/rssToGeoRSS?feedUrl=http://hosted.ap.org/lineups/WORLDHEADS-rss_2.0.xml?SITE=RANDOM&SECTION=HOME'); 
  3. Echo $file;
  4. ?>
You code is working perfectly on my side.

Did you check the setting for allow_url_fopen in php.ini as Atli suggested? What do you get from the following code?
[PHP]echo ini_get("allow_url_fopen");[/PHP]
Sep 28 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Gary | last post by:
I am trying to use the "System.Windows.Forms.SendKeys" class for triggering the Ctrl+P key. Syntax: System.Windows.Forms.SendKeys.Send("^(P)"); This is not working ..what could be the...
6
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
3
by: | last post by:
Hello, I am hoping someone else has thought about a date time calculation i need to perform. I would like to be able to calculate the number of "working minutes" between 2 dates, given my...
8
by: Hardy Wang | last post by:
Hi: Is it possible for me to create/open web application from remote machine other than port 80? And create application directly under virtual web site instead of creating a virtual directory?...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.