views:

25

answers:

2

Hi, I'm working on a web-app, in which each user has multiple non-local XML files that are downloaded and parsed via SimpleXML each page (re)load. Each request takes a little less than a second on average, however with more than five or six files (which is likely), the load time is quite noticeable. So my question is what factors go into the speed of the function and are there any was I could control and speed them up?

As for purely improving efficiency, http headers to check for the last-updated time are inaccurate and I don't think cron jobs would give me the 'live' results which I'm looking to get.

So are the factors mainly on the server that I'm accessing them from, or are they on my side? Is it the function itself? Obviously the size of the file affects the speed. Is there any way to compress it before bringing it over, thus speeding up downloads?

+1  A: 

What are your reasons for having them absolutely live? Could you have them updated every 15 minutes?

Could you Cron them and cache them for 15 minutes at a time?

You could make sure the method you get them from a remote server sends headers to accept gzip (and you can deflate them on your end).

alex
It's not ABOSLUTELY necessary, and I very well might have to give it up, but I'd rather not if I can get them in a reasonable time without. Could you send me a link where I could learn more about Cron with php?
WillyG
@iMaster They are pretty simple to set up. I just [searched Google](http://google.com/search?q=php+cron) and the results seem to be good enough to get started.
alex
Apparently, I can't edit my own comment, but I added the gzip stuff (thanks for that), didn't see much of an improvement, I guess some sites just don't gzip their files.
WillyG
@iMaster Yes it is unfortunate some do not. It would probably save a bit seeing as XML repeats a lot of stuff. Do any of their services offer their feeds in JSON? It is more lightweight, and PHP has `json_decode()` in built.
alex
I'll probably end up using cron jobs as you suggested, as that's been suggested twice.
WillyG
A: 

You may want to try curl_multi_init() if you have cURL installed. It will perform any number of requests in parallel, so a page that uses 5 or 6 requests shouldn't be much more slower than the one using only 1 or 2, especially if you arrange your code to start those requests as early in your script as possible.

With that said, it's still much worse than not performing any remote requests at all, obviously.

Josh Davis