davide101
05-04-2006, 05:55 PM
On my website, http://www.diabetesdaily.com, we have a script that aggregates content from a few dozen blogs. Every fifteen minutes, there's a pageload that takes about 15 seconds as the script deletes the cached RSS files and queries the new ones. I need to improve this and I have a few ideas but no clue how to implement them. There are two ways I can think of to improve this:
Method 1: Somehow display a "Loading Content" icon until the script is done running and then replace it with the actual content
Method 2: Run the script via a cron job every 15 minutes, somehow create a static file and include the static file
Is either these the right way to go? I'm a self-taught novice but I can get along well enough if you can offer a brief overview of what's necessary to accomplish this. I've had no luck trying to Google such a vague topic. :)
Thank you!
Vin0rz
05-04-2006, 06:42 PM
On my website, http://www.diabetesdaily.com, we have a script that aggregates content from a few dozen blogs. Every fifteen minutes, there's a pageload that takes about 15 seconds as the script deletes the cached RSS files and queries the new ones. I need to improve this and I have a few ideas but no clue how to implement them. There are two ways I can think of to improve this:
Method 1: Somehow display a "Loading Content" icon until the script is done running and then replace it with the actual content
Method 2: Run the script via a cron job every 15 minutes, somehow create a static file and include the static file
Is either these the right way to go? I'm a self-taught novice but I can get along well enough if you can offer a brief overview of what's necessary to accomplish this. I've had no luck trying to Google such a vague topic. :)
Thank you!
For Method 2, you'd have to create the cron job on the server, in the shell. Of course Wikipedia (http://en.wikipedia.org/wiki/Cron_job) has an article on them.
I think you'd have to do method 1 with Javascript because PHP is just for displaying the page, once it displays it execution stops. Maybe output buffering (search PHP.net) can help you?
ralph l mayo
05-04-2006, 08:39 PM
Method 2 is the way to go. crontab is pretty simple and generating static files has the added advantage of letting apache serve 'not modified' headers and saving you bandwidth.
edit: yeah, also, output buffering will make method 2 pretty easy:
ob_start();
// your old dynamic page
file_put_contents('static.xml', ob_get_contents());
You may need a bit more logic to determine the static filename, but that's basically the idea.
davide101
05-05-2006, 01:49 PM
Thanks for the advice - I had a feeling there was a simple way to do it if I could only figure out the function! I'm going to try method two this weekend. I'll let you know how it turns out.
davide101
05-05-2006, 06:03 PM
AWESOME! Ralph, your advice worked beautifully. Because I'm using PHP 4.1.x, I used the fopen, fwrite, and fclose sequence to make it happen. But it works. Now, I'm moving all of my RSS-processing scripts to their own static files and it's already having a dramatic effect.
Best wishes,
David