ob_start is a PHP function which turns output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.
Questions tagged [ob-start]
190 questions
21
votes
2 answers
PHP - nested output buffering
I have function that has :
ob_start();
//Include of some files
$content = ob_get_contents();
ob_end_clean();
Now in those includes is another function that uses the same code, and they seem to
conflict. Is it possible to use them like this?

somerandomusername
- 1,993
- 4
- 23
- 55
11
votes
4 answers
Cannot use output buffering in output buffering display handlers
I've reinstalled Apache, and switched from PHP 5.3 to 5.6. Everything works, except I get this error, when calling ob_start():
Cannot use output buffering in output buffering display handlers
I tried to enable output buffering in PHP, but I still…

Iter Ator
- 8,226
- 20
- 73
- 164
11
votes
7 answers
Methods ob_start and ob_flush don't work, why?
I am using ob_start()/ob_flush() to, hopefully, give me some progress during a long import operation.
Here is a simple outline of what I'm doing:
";
$conn = ftp_connect($ftp_site)…

MB34
- 4,210
- 12
- 59
- 110
11
votes
6 answers
why ob_start() must come ahead of session_start() to work in PHP?
I don't think it's reasonable.
Why is it actually such a rule?

omg
- 136,412
- 142
- 288
- 348
9
votes
3 answers
why do I need to end my ob_start()?
The php documentation suggests that I should end each ob_start() with an ob_end_flush(). I am using one on each page of a site, just to allow me to use firephp log methods anywhere in the app.
the app works fine, but I wonder if there is anything I…

Mild Fuzz
- 29,463
- 31
- 100
- 148
9
votes
2 answers
PHP's ob_flush() causing error
When I call PHP's ob_flush() function on my localhost (via MAMP) I get the following error:
Notice: ob_flush() [ref.outcontrol]:
failed to flush buffer. No buffer to
flush.
The only solution I can find is to prefix it with @, but this doesn't…

philfreo
- 41,941
- 26
- 128
- 141
8
votes
3 answers
ob_start() within a loop
I've got a problem when looping using foreach() loop and inside of this loop using ob_start() and ob_get_clean().
Here's my function:
protected function renderEmail() {
$template = $this->_case.".php";
if(is_file($this->_dir.DS.$template)) {
…

user398341
- 6,339
- 17
- 57
- 75
7
votes
1 answer
ob_start not executing callback
I'm having issues with ob_start. Not sure what the deal is, but I've bubbled it down to the simplest possible test case... still to no avail. I would expect this code to output 'bar' to the stdout, but I'm getting nothing back, and no errors in my…

John Green
- 13,241
- 3
- 29
- 51
6
votes
3 answers
PHP ob_start vs opcode APC, explain differences and real world usage?
Premise: I'm not trying to reinvent the wheel, I'm just trying to understand.
Output caching can be implemented easily:
//GetFromMyCache returns the page if it finds the file otherwise returns FALSE
if( ($page = GetFromMyCache($page_id)) !== FALSE…

Marco Demaio
- 33,578
- 33
- 128
- 159
5
votes
1 answer
PHP: ob_start(), how to limit callback
How does one stop calls to the ob_start callback when issue-ing *_clean() calls.
ob_start(function($buffer, $phase){
// code here
}, 0, PHP_OUTPUT_HANDLER_FLUSHABLE | PHP_OUTPUT_HANDLER_REMOVABLE);
Doesn't prevent ob_end_clean, ob_get_clean or…

Krotz
- 615
- 3
- 9
- 21
5
votes
1 answer
How to pass a callback function with parameters for ob_start in PHP?
I've been following this tutorial on a caching function. I run into a problem of passing the callback function cache_page() for ob_start. How can I pass cache_page() along with two paramters $mid and $path to ob_start, something along the lines of
…

RedGiant
- 4,444
- 11
- 59
- 146
5
votes
2 answers
Is ob_start useless when there is no output?
I just saw a link on here with pretty much the same issue I had, but I want to make sure I understand. Here's the link:
what is the role of ob_start() in here
So, his code had no real "output" -- no echos, no html, pretty much nothing. But he had an…

McAuley
- 413
- 1
- 3
- 13
4
votes
2 answers
how to start ob_start inside a class?
im doing a little reasearch about minimalizing the html from php. like
class themeing
{
function render( $file, $folder )
{
if ( COMPRESS ) {
// this is the problem
ob_start('compressor');
}
…

Adam Ramadhan
- 22,712
- 28
- 84
- 124
4
votes
0 answers
php ob_start with function that uses die?
I have the following code:
function a(){ die( 'some text' ) }
ob_start();
a();
$return = ob_get_clean();
echo 'result:'
var_dump( $return );
and it doesn't work.
I get some text in my browser.
How can I make it work? How can I catch die() in a…

Maikal
- 247
- 2
- 11
4
votes
2 answers
PHP ob_start: callback a static method with $this
With PHP's ob_start($callback), you can pass a static method as a callback like this:
class TemplateRenderer {
function myCallback($bufferContents) {
return 'Foobar instead of the buffer';
}
}
ob_start(array('TemplateRenderer',…

DMack
- 871
- 2
- 9
- 21