Disadvantages of output buffering

Disadvantages of output buffering

am 26.06.2007 14:33:09 von Emil Edeholt

Hi!

My php project would get a much cleaner code if I could set cookies
anywhere in the code. So I thought of output buffering. But I can't find
any articles on the cons of output buffering. I mean it most be a reason
for it being off by default?

Kind Regards Emil Edeholt

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

Re: Disadvantages of output buffering

am 26.06.2007 15:04:06 von Robert Cummings

On Tue, 2007-06-26 at 14:33 +0200, Emil Edeholt wrote:
> Hi!
>
> My php project would get a much cleaner code if I could set cookies
> anywhere in the code. So I thought of output buffering. But I can't find
> any articles on the cons of output buffering. I mean it most be a reason
> for it being off by default?

Cons of output buffering:

- teeeeeeeency weency time overhead
- memory overhead since buffered content remains in memory
until flushed.

Cheers,
Rob.
--
..---------------------------------------------------------- --.
| InterJinn Application Framework - http://www.interjinn.com |
:----------------------------------------------------------- -:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`----------------------------------------------------------- -'

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

Re: Disadvantages of output buffering

am 26.06.2007 15:07:21 von Emil Edeholt

Thanks for your help Dave and Rob. I will start using output buffering a
lot more now.

Regards Emil

Robert Cummings wrote:
> Cons of output buffering:
>
> - teeeeeeeency weency time overhead
> - memory overhead since buffered content remains in memory
> until flushed.
>
> Cheers,
> Rob.
>

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

Re: Disadvantages of output buffering

am 26.06.2007 15:09:13 von Stut

Robert Cummings wrote:
> On Tue, 2007-06-26 at 14:33 +0200, Emil Edeholt wrote:
>> Hi!
>>
>> My php project would get a much cleaner code if I could set cookies
>> anywhere in the code. So I thought of output buffering. But I can't find
>> any articles on the cons of output buffering. I mean it most be a reason
>> for it being off by default?
>
> Cons of output buffering:
>
> - teeeeeeeency weency time overhead

Compared to the time taken to flush to the client more often? This is
incorrect in most cases, and even when it's not it really really is
"teeeeeeeency weency".

> - memory overhead since buffered content remains in memory
> until flushed.

Indeed, but memory is cheap and you're likely to run out of memory for
other reasons waaaaay before output buffering causes it.

-Stut

--
http://stut.net/

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

Re: Disadvantages of output buffering

am 26.06.2007 15:12:27 von Robert Cummings

On Tue, 2007-06-26 at 14:09 +0100, Stut wrote:
> Robert Cummings wrote:
> > On Tue, 2007-06-26 at 14:33 +0200, Emil Edeholt wrote:
> >> Hi!
> >>
> >> My php project would get a much cleaner code if I could set cookies
> >> anywhere in the code. So I thought of output buffering. But I can't find
> >> any articles on the cons of output buffering. I mean it most be a reason
> >> for it being off by default?
> >
> > Cons of output buffering:
> >
> > - teeeeeeeency weency time overhead
>
> Compared to the time taken to flush to the client more often? This is
> incorrect in most cases, and even when it's not it really really is
> "teeeeeeeency weency".
>
> > - memory overhead since buffered content remains in memory
> > until flushed.
>
> Indeed, but memory is cheap and you're likely to run out of memory for
> other reasons waaaaay before output buffering causes it.

Agreed, I was hard pressed to come up with cons in the first place :)

Cheers,
Rob.
--
..---------------------------------------------------------- --.
| InterJinn Application Framework - http://www.interjinn.com |
:----------------------------------------------------------- -:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`----------------------------------------------------------- -'

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

Re: Disadvantages of output buffering

am 26.06.2007 15:54:23 von Robin Vickery

On 26/06/07, Robert Cummings wrote:
> On Tue, 2007-06-26 at 14:09 +0100, Stut wrote:
> > Robert Cummings wrote:
> > > On Tue, 2007-06-26 at 14:33 +0200, Emil Edeholt wrote:
> > >> Hi!
> > >>
> > >> My php project would get a much cleaner code if I could set cookies
> > >> anywhere in the code. So I thought of output buffering. But I can't find
> > >> any articles on the cons of output buffering. I mean it most be a reason
> > >> for it being off by default?
> > >
> > > Cons of output buffering:
> > >
> > > - teeeeeeeency weency time overhead
> >
> > Compared to the time taken to flush to the client more often? This is
> > incorrect in most cases, and even when it's not it really really is
> > "teeeeeeeency weency".
> >
> > > - memory overhead since buffered content remains in memory
> > > until flushed.
> >
> > Indeed, but memory is cheap and you're likely to run out of memory for
> > other reasons waaaaay before output buffering causes it.
>
> Agreed, I was hard pressed to come up with cons in the first place :)

Modern browsers often start partially rendering HTML as soon as it
arrives rather than waiting for the page to load completely.
Obviously, if you're waiting until the end of the script before
actually sending any HTML, they can't do that so your page might
appear less responsive.

-robin

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

Re: Disadvantages of output buffering

am 26.06.2007 16:14:12 von William Lovaton

These two reasons are in fact of little impact.

The real problem I have with output buffering in my web app is that it
doesn't handle .xls and .pdf files generated on the fly with PHP. Every
time the browser is going to download those kind of files it will get
corrupted.

The only solution I could find for this was to disable output buffering.

Another thing: you can even compress the buffer before sending it so it
will help a lot if a user have little bandwidth. Text files have a very
good compression ratio.

Cheers,


-William


On Tue, 2007-06-26 at 09:04 -0400, Robert Cummings wrote:
> On Tue, 2007-06-26 at 14:33 +0200, Emil Edeholt wrote:
> > Hi!
> >
> > My php project would get a much cleaner code if I could set cookies
> > anywhere in the code. So I thought of output buffering. But I can't find
> > any articles on the cons of output buffering. I mean it most be a reason
> > for it being off by default?
>
> Cons of output buffering:
>
> - teeeeeeeency weency time overhead
> - memory overhead since buffered content remains in memory
> until flushed.
>
> Cheers,
> Rob.
> --
> .----------------------------------------------------------- -.
> | InterJinn Application Framework - http://www.interjinn.com |
> :----------------------------------------------------------- -:
> | An application and templating framework for PHP. Boasting |
> | a powerful, scalable system for accessing system services |
> | such as forms, properties, sessions, and caches. InterJinn |
> | also provides an extremely flexible architecture for |
> | creating re-usable components quickly and easily. |
> `----------------------------------------------------------- -'
>

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

Re: Disadvantages of output buffering

am 03.07.2007 09:21:23 von Richard Lynch

On Tue, June 26, 2007 7:33 am, Emil Edeholt wrote:

> My php project would get a much cleaner code if I could set cookies
> anywhere in the code. So I thought of output buffering. But I can't
> find
> any articles on the cons of output buffering. I mean it most be a
> reason
> for it being off by default?

Main reason to be off by default is backwards compatibility.

Depending on your PHP, HTML and/or CSS and browser rendering, output
buffering can also make a site "seem" slow since it buffers up all the
output until the page is complete.

But you'd have to have some pretty heavy lifting in PHP buried in the
middle of the HTML output for that to be meaningful. That's usually a
bad Design decision, but there might be some cases where it's
relevant.

There also have been a lot of benchmarks to prove buffering was
better/worse/faster/slower. You're on your own about which ones to
believe.

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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

Re: Disadvantages of output buffering

am 03.07.2007 09:23:43 von Richard Lynch

On Tue, June 26, 2007 8:54 am, Robin Vickery wrote:

CON:

On a dev server, when you screw up and write an infinite loop, PHP
spends a hell of a lot more time spinning its wheels before you kill
it because your infinitely long output is all buffered up.

[innocent voice]
Not that that has ever happened to me, oh no.
[/innocent]

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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

Re: Disadvantages of output buffering

am 03.07.2007 15:41:18 von Robert Cummings

On Tue, 2007-07-03 at 02:23 -0500, Richard Lynch wrote:
> On Tue, June 26, 2007 8:54 am, Robin Vickery wrote:
>
> CON:
>
> On a dev server, when you screw up and write an infinite loop, PHP
> spends a hell of a lot more time spinning its wheels before you kill
> it because your infinitely long output is all buffered up.
>
> [innocent voice]
> Not that that has ever happened to me, oh no.
> [/innocent]

I'm sorry but your SQUAREML is poorly formed. I was unable to parse your
message. Please resend according to webservice specs.

;)

Cheers,
Rob.
--
..---------------------------------------------------------- --.
| InterJinn Application Framework - http://www.interjinn.com |
:----------------------------------------------------------- -:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`----------------------------------------------------------- -'

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

Re: Re: Disadvantages of output buffering

am 29.08.2007 21:19:20 von Richard Lynch

On Tue, August 28, 2007 6:40 pm, Felipe Alcacibar wrote:
> Emil Edeholt wrote:
>> Hi!
>>
>> My php project would get a much cleaner code if I could set cookies
>> anywhere in the code. So I thought of output buffering. But I can't
>> find
>> any articles on the cons of output buffering. I mean it most be a
>> reason
>> for it being off by default?
>>
>> Kind Regards Emil Edeholt
>
>
> The output buffering maybe would be unstable your php application in
> some cases. May be it so slowly in some versions of php and depend of
> the web server that you have mounted your php. And it uses memory this
> point is so clearly.
>
> If you want to create cookies server/client "on the fly" you may need
> ajax, with this asynchronus requests you put headers and cookies
> instead, and use it on the fly in the browser if the http request is
> ok.
>
> Are you know the session variables, maybe you need that.
>
> Well, the desicion is yours. tell us what you want to do.

It's probably off by default for a couple reasons:

#1. It didn't used to exist, so to be backwards-compatible, it's off.

#2. It does chew up a lot of RAM for a large HTML file, which if you
don't need it, is Bad.

#3. Your page can seem to be "slow" if it's fairly large, and laid out
to not require the whole page to render the first portion of the page.
(No tables, and probably no CSS, just old-school simple HTML).

Note, however, that if you have a lot of little echo statements,
output buffering can actually improve overall performance, since it
doesn't dink around with sending a few bytes at a time and switching
back and forth from output to calculations. Depends on your
application and a whole host of other variables.

--
Please vote for this great band:
http://acl.mp3.com/feature/soundandjury/?band=COMPANY-OF-THI EVES

Requires email confirmation.
One vote per day per email limit.
Obvious ballot-stuffing will be revoked.

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