user3741635
user3741635

Reputation: 862

Why does it take longer time to view xml file in PHP than using Browser?

I am trying to echo this xml file http://export.arxiv.org/rss/hep-th in my webpage using

echo file_get_contents('http://export.arxiv.org/rss/hep-th');

This takes a long time to load and most of the time it even exceeds 30. However when I load the same url using my browser it takes less than 2 seconds to show the same file. Do these files usually take this long or am I doing something wrong?

Upvotes: 0

Views: 77

Answers (1)

hakre
hakre

Reputation: 197682

Both file_get_contents and readfile with a HTTP-URI like the URL you've got in your question will use the same HTTP stream wrapper in PHP. So both methods will do the more or less same HTTP operations in the background.

That's similar with your browser, however as the HTTP protocol can have many facets, it can be (and most likely is) that your browser sends a different HTTP request than your PHP configuration.

Depending on the HTTP service you interact with via the HTTP protocol, it might process some headers (or the absence of them) that differently, that it for example waits 30 seconds before providing an answer.

But it can also be, that it tries to serve data fresh when you request via PHP but will provide cached content when you access via the browser so that the reason of why some response might take more seconds to be ready than another response.

From your question alone it can not be said what the reason in concrete is as we can not look into the service itself.

You can perhaps find out more by contacting the vendor of the HTTP service you make use of and ask their support why responses differ so greatly in response-time.

Upvotes: 1

Related Questions