# Output Buffering/Register Shutdown Function

**URL:** <https://forum.kirupa.com/t/output-buffering-register-shutdown-function/269319>\
**Category:** programming\
**Created:** [August 26, 2008, 6:36am UTC](https://forum.kirupa.com/t/output-buffering-register-shutdown-function/269319 "2008-08-26T06:36:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)\
**Post date:** [August 26, 2008, 6:36am UTC](https://forum.kirupa.com/t/output-buffering-register-shutdown-function/269319/1 "2008-08-26T06:36:38Z")

</div>

Hi, Im using PHP 4.4 in a CMS. I have an ob\_start() and a function

```php

function endBuffer(){
		
		$buffer = ob_get_contents();
		ob_end_clean();
		
		$buffer = displayBuffer($buffer);
		
		echo $buffer;
		
}

```

Initially I was just doing ob\_start(‘displayBuffer’); but i learnt i cant use output buffers in the ob\_start callback (displayBuffer).

So, I put everything in endBuffer and tried to call that using register\_shutdown\_function(endBuffer) but it looks like, on shutdown, the buffer is already flushed?

How can I set this up so that the endBuffer function gets called at the end of the script, but before it automatically gets flushed?
