* Thus wrote Marek Kilimajer:
> Eduard Duran i Rosich wrote:
> >Hi,
> >I just wanted to know what are the main pros and cons between echoing
> >the output some PHP script as it process the data and returning the
> >whole output to echo it at once.
> >I find the second way to be useful when I want to add a header() line
> >without concerning former output.
> >However, is that way slower or has any other inconvenience?
> 
> If you decide to output everything at the end, it will seem that there 
> is no responce from the server for pages that take longer to build. Some 
> impatient visitors will try refresh buttons, thus adding more load to 
> the server.

To add to this, there is also memory usage. If you build up your
output in a buffer before sending it you are basically doubling
the required memory needed to send the output.

My philosophy is to send the data as soon as possible with as
little memory consumed, a general layout of script i'll create is
something like:
<?php

// authenticate if needed
// redirect if needed
// determain simple information like, title of page, etc.

/* the above stuff shouldn't take any significant amount of time */

?>
<!DOCTYPE...>
<html>
<head>
<title><?php echo $page_title?></title>
...
<div id="leftnav">
<?php // generate left nav ?>
</div>
<div id="content">
<?php // generate content ?>
</div>
<?php

// any stuff to be done here
?>

imo, If your logic requires you to redirect at the end of generating a
page, your logic needs to be reworked.


Curt
-- 
The above comments may offend you. flame at will.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to