tags:

views:

31

answers:

1

I have noticed on my little web server that if a user clicks a link while my php script is outputting data from a database that the web site seems to lock up for a while and the server log shows that "Maximum execution time of 30 seconds exceeded in" etc etc. If I create a big string and output that is does not seem to happen but im guessing it is still possible.

So if I do this is seems ok:

$html_blob = '';

list($result,$dbhandle,$num) = db_connect($sql);

$html_blob .= 'Here is some data:<br />';

while($row = mssql_fetch_array($result)) {
    $html_blob .= $row['first_name'].','.$row['last_name'].'<br />';
}

echo $html_blob;

If I do this I can get the temporary lockup to happen if I click a link while in the while loop:

list($result,$dbhandle,$num) = db_connect($sql);

echo 'Here is some data:<br />';

while($row = mssql_fetch_array($result)) {
    echo $row['first_name'].','.$row['last_name'].'<br />';
}

Is there any recommended best practice for long (or short even) lists? Should I always concatenate a string then output that instead?

A: 

Build the HTML within a string first then echo at the end, or look at output buffering the page with ob_start(); and related functions see: http://www.php.net/manual/en/ref.outcontrol.php

D Roddis