Computing.Net > Forums > Programming > php output buffering

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

php output buffering

Reply to Message Icon

Name: OneSideZero
Date: June 9, 2006 at 00:06:06 Pacific
OS: -
CPU/Ram: -
Product: -
Comment:

can someone explain to me what ob_start() does? I have a vague idea its got something to do with buffering output.

i've seen it in all dynamic image creation scripts, so i figured i might as well use it, but i want to know why!

how and why is it used in this example...

header("Content-Type: image/jpeg");

$imageData = <get image data from database>

<resizing etc>

$src = imagecreatefromstring($imageData);

$img = imagecreatetruecolor($new_w,$new_h);

imagecopyresized($img,$src,0,0,0,0,$new_w,$new_h,$w,$h);

ob_start();

imagejpeg($img);

ob_end_flush();

imagedestroy($img);


thanks for the info...



Sponsored Link
Ads by Google

Response Number 1
Name: anonproxy
Date: June 9, 2006 at 13:36:55 Pacific
Reply:

Simple. ob_start() opens a buffer and pipes all script output into the buffer. The typical script output is text (e.g. from echo statements).

In the example you cite, an image is being created and printed directly to output (imagejpeg() does that when no file path is specified). Since the buffer is opened before imagejpeg() is called, the image goes into the buffer. Of course, flushing the buffer gets rid of this. Regardless, that is what the code is doing.


0

Response Number 2
Name: OneSideZero
Date: June 14, 2006 at 15:02:09 Pacific
Reply:

yea but whats the point, i see no difference in performance or anything


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Microsoft Access Joins Manipulating componf term...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: php output buffering

Pipeline and IO buffer problem ... www.computing.net/answers/programming/pipeline-and-io-buffer-problem-/6956.html

getch() is called before it should www.computing.net/answers/programming/getch-is-called-before-it-should/5744.html

Simple C++ Question www.computing.net/answers/programming/simple-c-question/4449.html