8

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!?

2

4 Answers 4

2

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

2
  • Is this still the case, the issue is closed and no fix that I can find in 1.9.2.4? Commented Jul 8, 2016 at 18:41
  • 1
    According to note yesterday, this issue "closed when ver. EE 1.14.3.0/CE 1.9.3.0 is released" - and you were specifically noted in JIRA, @AaronBonner ;-)
    – benmarks
    Commented Jul 9, 2016 at 12:28
1

lol I solved my problem change this in:

/app/code/local/Cmsmart/Megamenu/Block/Navigation.php

/*
* Name Extension: Megamenu
* Version: 0.1.0

for:

/**
* Name Extension: Megamenu
* Version: 0.1.0

-.-

1
  • So, general incompetence in the php interpreter somewhere that's being used on your website that makes it not realize /* to be a php comment unless it has another *? Commented Jun 21, 2016 at 15:46
0

I have the same problem while installing Magento. In my case enabling output_buffering in PHP solved the issue. In xampp with PHP 5.6 output_buffering is enabled by default. In xampp with PHP 5.3 output_buffering is disabled by default.

0

For reference the issue can be reproduced by uploading some png files using the admin cms/wysiwyg editor then seeing a list of thumbnails.

I've hacked that thumbnail action to use output buffering and use the response object to set the data body and correct Content-Type (there's another bug there where the code is setting the gd file type id rather than the mimetype).

The code below replaces the method of the same name in app/code/core/Mage/Adminhtml/controllers/Cms/Wysiwyg/ImagesController.php. Use whatever mechanism you prefer to override this method (I used a local code pool controller override).

/** * Generate image thumbnail on the fly */ public function thumbnailAction() { $file = $this->getRequest()->getParam('file'); $file = Mage::helper('cms/wysiwyg_images')->idDecode($file); $thumb = $this->getStorage()->resizeOnTheFly($file); if ($thumb !== false) { $image = Varien_Image_Adapter::factory('GD2'); $image->open($thumb); ob_start(); $image->display(); $imageData = ob_get_contents(); ob_end_clean(); $mimeType = image_type_to_mime_type($image->getMimeType()); $this->getResponse()->setHeader('Content-Type', $mimeType, true); $this->getResponse()->setBody($imageData); } else { // todo: genearte some placeholder } }

I'll maintain a gist as well, here - https://gist.github.com/ajbonner/94c8e61705bb7aa3e6feca4461d85595

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.