Output buffering on shared server


#1

I noticed my output buffering wasn’t working on my shared Dreamhost server. I have a very simple PHP script to test it:

<?php ob_start(); echo 'should be buffered
'; $buffered = ''; while(ob_get_level() > 1) { $buffered .= ob_get_clean(); } echo 'yep
'.$buffered; ?>

This doesn’t work properly. Or an even simpler example:

<?php ob_start(); echo (ob_get_level() > 1) ? 'buffering on':'buffering off'; ?>

Does anyone know what I need to do? Is output buffering possible on a shared server?


#2

ob_get_level() starts at the value 0. After the ob_start() it becomes 1. So it actually works as expected.

On other hosts the ob_get_level() might be 1 at the start, if output buffering is on by default.


#3

Thanks for the reply! You’re right, it was just a silly mistake.