Forum Moderators: coopster

Message Too Old, No Replies

ob_start etc

         

Code Sentinel

4:47 pm on Sep 16, 2004 (gmt 0)

10+ Year Member



is ob_end_flush required at the end of the script when you use ob_start at the beginning? or will the contents of the buffer be output when the script is finished executing regardless if ob_end_flush is called or not?

I'm trying to clean up my code but currently have ob_end_flush included at the bottom of every page/script and was wondering if it was even needed. Will the content of the buffer will be output at end of script execution even if ob_end_flush wasn't included?

mincklerstraat

5:02 pm on Sep 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



best answer would be to read the complete page and comments at [be2.php.net...] . I don't believe output will go to the user if you don't use ob_flush, though I don't think I've ever tried. Even if it does, this might be 'non-standard' behavior since it isn't explicitly documented with the function in the manual, and could be subsequent to change in the future.

Safest practice probably the following:
declare a function echoit() in some central file that gets called by all your scripts -
echoit($var){
echo $var;
}
and instead of ob_start(), try ob_start('echoit') (using echoit as the callback).
When used with a callback, ob_start sends the output at the end to this function.

And another thought: if you've got php installed on your local box, it's like 30 seconds and you have the answer to your own question. One place to get it: [apachefriends.org...] ('wow! apache has got some pretty hip-looking friends')

Code Sentinel

5:22 pm on Sep 16, 2004 (gmt 0)

10+ Year Member



I was wondering what callback was exactly, still a lightweight with php (no previous programming knowledge).

that wamp setup looks good compared to the basic one I have setup. I guess I'll have to do some tests.

ergophobe

8:21 pm on Sep 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A lot of PHP functions allow callback functions which, as you now know, are functions that act on the results returned from the built-in function. In addition to ob_start(), some others are

- preg_replace_callback()
- array_walk()
- array_filter()
- lots more array functions
- xml_set_element_handler()
- etc etc

Code Sentinel

10:13 pm on Sep 19, 2004 (gmt 0)

10+ Year Member



did some quick tests with a test page that just displayed phpinfo.

I removed ob_end_flush and everything still worked and the output was sent to the browser after ob_start and even a nested ob_start worked without ob_end_flush for either.

One oddity I couldn't quite figure out was that I was able to echo functions like ob_get_length as long as the ob_end_flush wasn't called for either of the ob_start and nested ob_start. Yet if I put the ob_end_flush in the right spots then I couldn't echo it and it would actually cut short the output. In this case I was using phpinfo() and it stopped displaying everything after "Apache Environment" when using ob_end_flush and when not using ob_end_flush it echo'd the ob_get_length function and displayed the full phpinfo().

So basically it works without ob_end_flush.. I'm not sure how it does it.. and it seems to give more flexibility with regards to display.. but technically it's wrong without ob_end_flush. Maybe the server I was testing on was setup wrong. :P

Where can I find more information on php callback, I'm not sure exactly what it is but sort of understand how it might work.