/    Sign up×
Community /Pin to ProfileBookmark

file_get_contents() keeps timing out

I am making an API which responds to incoming requests by returning xml files. So for example if I go to:

[url]http://localhost/fpapi/fpapi.php?method=film.getTop[/url]

I get an xml file:

<fpapiresponse type=”success”>
<film>
<id>10875721</id>
<title>Moon</title>
<tagline>The last place you’d ever expect to find yourself</tagline>
<description>Astronaut Sam Bell has a qui…

It works fine in this mode of operation, but I need to be able to make requests to the API from within a PHP script. That is, I need to be able to open the url above and read the contents of the returned xml file so that I can the data in the PHP script.

Following ‘Example #1’ from [url]http://uk.php.net/manual/en/context.http.php[/url] I am creating a context resource with the encoded post data and then trying to do file_get_contents() on the url of a method in the API.

It just times out. Is the server is making a request to itself? Or is it because I am making the request in the wrong way?

Please ask any further questions if you need me to clarify anything.

Thanks, this is a major problem for me which I really had not anticipated ?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@sneakyimpJul 23.2010 — 'localhost' means something different on your desktop computer or laptop than it means to your server. For any computer trying to access localhost, that means [I]itself[/I].

I find myself wondering if your script is timing out or if file_get_contents is permitted to open a remote url on your machine.
Copy linkTweet thisAlerts:
@criterion9Jul 24.2010 — If you are restricted to local filesystem for fil_get_contents you can usually use curl to achieve the same effect (plus it allows you to adjust timeouts and such).
×

Success!

Help @Mbon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...