Magento – How to fix: “HEADER ALREADY SENT” and GD2

gd2headerimage

This is a follow on to the question on How to debug: HEADER ALREADY SENT and GD2. Specifically how to fix the following errors (note first line had been added using previous debug advice to track the source):

   2014-02-04T14:26:06+00:00 DEBUG (7): Cannot send headers; headers already sent in /home/.../lib/Varien/Image/Adapter/Gd2.php, line 133
   2014-02-05T16:14:32+00:00 DEBUG (7): HEADERS ALREADY SENT: < pre >
    [0] /home/.../app/code/core/Mage/Core/Controller/Response/Http.php:52
    [1] /home/.../lib/Zend/Controller/Response/Abstract.php:766
    [2] /home/.../app/code/core/Mage/Core/Controller/Response/Http.php:83
    [3] /home/.../app/code/core/Mage/Core/Controller/Varien/Front.php:188
    [4] /home/.../app/code/core/Mage/Core/Model/App.php:354
    [5] /home/.../app/Mage.php:683
    [6] /home/.../public_html/index.php:87
    </ pre >

That question was about how to debug this issue. This question is on how to fix it. As per my "answer" on that question, and having done some further tests on a vanilla Magento install, I can confirm that this does appear to be a Magento core bug (v1.7.0.2).

Simply managing images on pages or static blocks, using the standard Magento page/block image manager causes these logs. To reproduce, open a page that has images on it. There will be one of these logged per image on the page. Open the image manager and view uploaded images – there will be another for each image displayed.

The problem seems to be with this function, which on my reading will most certainly cause this error any time a CMS image is fetched for display in the dashboard.

public function display()
    {
        header("Content-type: ".$this->getMimeType());
        call_user_func($this->_getCallback('output'), $this->_imageHandler);
    }

While it doesn't appear to have any impact on the store, I'd rather not treat this as a "benign error" (as Microsoft like to call things they can't get right/fix!). I guess we could just modify canSendHeader() in lib/Zend/Controller/Response/Abstract.php to not throw an error if $file is gd2.php, but that's just a nasty kludge!

What it looks like is at some point before canSendHeaders is called as part of displaying CMS images in the dashboard, either $throw or $this->headersSentThrowsException should be set false so this doesn't generate an exception.

Any ideas? Or this is this something Magento owners have learnt to live with!?

Best Answer

This issue will be patched at some point; reference MPERF-7047.