Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Display result of slow script after page loads

    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!

  • #2
    Regular Coder
    Join Date
    Feb 2006
    Location
    The Netherlands
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by davide101
    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 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?
    Yeah that.

  • #3
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    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:
    PHP Code:
    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.
    Last edited by ralph l mayo; 05-04-2006 at 09:42 PM.

  • #4
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •