开发者

PHP and Database Output . Lockup during one method but not the other

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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜