4

I have this problem with Headers already sent with Magento. I get this error:

HEADERS ALREADY SENT: 
[0] /var/www/etam/trunk/src/app/code/core/Mage/Core/Controller/Response/Http.php:44
[1] /var/www/etam/trunk/src/lib/Zend/Controller/Response/Abstract.php:727
[2] /var/www/etam/trunk/src/app/code/core/Mage/Core/Controller/Response/Http.php:75
[3] /var/www/etam/trunk/src/app/code/core/Mage/Core/Controller/Varien/Front.php:188
[4] /var/www/etam/trunk/src/app/code/core/Mage/Core/Model/App.php:304
[5] /var/www/etam/trunk/src/app/Mage.php:596
[6] /var/www/etam/trunk/src/index.php:139

I saw this topic but didn't help me much.

I have found that this log I get only when navigating through Admin Panel and going to edit pages with WYSIWYG editor. When in the content of such edit there are .jpg images then I get this headers already sent error.

As far as I discovered it is not for all images but for some of them. For example when there is only 1 image no error then. When there are 3 of them, just for one I get this error.

I can't find any white spaces or unwanted echo nor print. I'm stuck with this and I'm out of ideas what to search for. Maybe you could give me some advices? I know it is harmless, still we don't want to have any errors in system.log.

Hitendra
  • 47
  • 8
Ventus
  • 2,482
  • 4
  • 35
  • 41
  • I don't know if you had the same problem as me, but I solved it using the path of the images instead of calling them with the {{media url="/something.jpg"}} – Matteo May 11 '12 at 15:54

3 Answers3

10

Sometimes we see "Headers Already Send..." in system.log... to prevent this we should return our data in controllers with one of those methods

clean way:

$this->getResponse()->setBody($response);

or dirty way:

echo $response;

exit();

There are some cases where "clean way" doesn't work, so we must use "dirty way".

Use this if You're getting content via Ajax, like it's done in CMS ;)

xyz
  • 2,277
  • 2
  • 25
  • 41
  • I knew about this Response object, yet I didn't think of just using `exit()`. Well, keep learning something new every day :) Thanks mate. – Ventus Mar 15 '11 at 15:42
  • The _dirty way_ is the only way that works for me when outputing TCPDF. – kiatng Mar 17 '18 at 06:11
0

Alternatively we could overwrite \app\code\core\Mage\Adminhtml\controllers\Cms\WysiwygController.php in the same way Magento 1.9.3 does it. In our case this was changing this part of the function directiveAction()

        try {
        $image = Varien_Image_Adapter::factory('GD2');
        $image->open($url);
        $image->display();
    } catch (Exception $e) {
        $image = Varien_Image_Adapter::factory('GD2');
        $image->open(Mage::getSingleton('cms/wysiwyg_config')->getSkinImagePlaceholderPath());
        $image->display();

to

        try {
        $image = Varien_Image_Adapter::factory('GD2');
        $image->open($url);
    } catch (Exception $e) {
        $image = Varien_Image_Adapter::factory('GD2');
        $image->open(Mage::getSingleton('cms/wysiwyg_config')->getSkinImagePlaceholderPath());
    }
    ob_start();
    $image->display();
    $this->getResponse()->setBody(ob_get_contents());
    ob_end_clean();

Further information (in German) right here. Verified with Magento CE 1.9.2.4.

0

Oddly, I created this post just this morning since I ran into a very similar problem when debugging Magento.

http://codemagento.com/2011/03/debugging-headers-already-sent-error/

  • Thanks for your replay, but I have already found the line where headers are sent and it doesn't make much sense to me. Because in Varien_Image_Adapter_Gd2 line 115 is `call_user_func($this->_getCallback('output'), $this->_imageHandler);`. `imagejpeg` is called there, which suppose to send .jpg image to the browser. The strange thing is that it only throws headers for some pictures, not for all in WYSIWYG editor. Either way, thanks for your answer. – Ventus Mar 15 '11 at 09:36
  • @Ventus we see the same - I think it has to do with spaces in the filename – snh_nl Jan 19 '16 at 09:36