Jump to content

[SOLVED] Displaying parts of a page while the page is not complete yet


Recommended Posts

A script I'm writing outputs a HTML table with many rows. Each row is the result of a query which takes about one minute to perform. When I run the script in a browser, the page takes several minutes to load and then displays the entire table. Is it possible (using PHP) to display the table as it gets constructed, one row at a time?

 

A page that does this is http://www.b3ta.cr3ation.co.uk/site/music-plus/ but I don't know if it uses PHP for this.

Not sure about this, but maybe if you give your table an absolute width, and als each row the same, then the browser might output faster as it doesnt have to recalculate fixed proportions depending on the output.

 

One minute pr row? Damn...

 

You could also try to make each row it's own table.

Your script does actually output data after each query, right? Not making one big variable to put out at the end?

 

Yes, output after each query. I got rid of the table, and just echo the data now, it looks like this:

 

foreach($array as $item)
{
    $result = get_data_for_item($item); // this takes 1 minute
    echo $result . "<br>";
}

 

But it's still the same as before: If $array has 10 items, the page loads 10 minutes and then displays all results.

Did a check and its the same on my server too. Havent really thought too much about this before now, but you got me a bit curious. Seems php does it's work and outputs when its all done. I'm guessing this behaviour can be changed through setting som custom php.ini variables, and will look into it tomorrow some time. Maybe someone else has the solution for you before then.

I asked this question on another forum, and someone there knew the solution: Simply call ob_flush() and then flush() in order to push all output that has been produced so far to the client. My code now looks like this and works perfectly :)

 

foreach($array as $item)
{
    $result = get_data_for_item($item); // this takes 1 minute
    echo $result . "<br>";
    ob_flush();
    flush();
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.