Usage of ob_start() in fixing one-page checkout issues

One page checkout steps are so sensitive that even a single character echoed from anywhere (due to some mistakes or PHP errors) will make your checkout steps not working.

I just recently faced one issue: One-page checkout was not redirecting to order confirmation page after clicking on Place Order button (Review Page). When I checked the console via firebug i found the following ajax response:

f{"success":true,"error":false}

You can note there is extra character ‘f’ which makes the JSON response invalid and the opcheckout.js can’t operate properly & hence no further redirection to third party or order confirmation page.

Since the client was in rush, i solved the issue using the concept of ob_start() function of php as:
File: app/code/core/Mage/Checkout/OnepageController.php

public function saveOrderAction() 
{
    ob_start();
    //....
    $outputBuffer = ob_get_contents();
    ob_end_clean();
    Mage::log('outputTrapped::' . $outputBuffer, null, 'onepagecheckout.log');
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}

By using the ob_start() on the start of the function, output are captured in the buffer instead of direct output to the browser.

I know best bet is to find the related place and prevent the direct output to the browser but I just posted this as an example on dealing with ob_start() in case of one-page checkout steps.

Hope this gave some idea.