If the following error message appears in the system log file var/log/system.log: DEBUG (7): HEADERS ALREADY SENT: <pre>[0] PATH_TO_MAGENTO_INSTALLATION\app\ code\core\Mage\Core\Controller\Response\Http.php:53, the first step is to find the location where the error actually occurs, since Http.php is only the downstream component. To do this, we add, for example, the following to the file
\lib\Zend\Controller\Response\Abstract.php
in the function
public function canSendHeaders($throw = false)
these two lines to output the filename and line number:
Mage::log('File: ' . $file);
Mage::log('Line: ' . $line);
In our case, the culprit is the file
\lib\Varien\Image\Adapter\Gd2.php
and specifically the function
public function display()
We could also insert the directive
Mage::log(print_r(get_included_files(),true));
in the aforementioned Http.php, but in that case we would spend weeks examining the entire list of files that had been included up to that point.
But where is this display() function actually called? Among other places, in
\app\code\core\Mage\Adminhtml\controllers\Cms\WysiwygController.php
in the function
public function directiveAction()
Along the way, we came across several threads describing this issue. Among other things, we found in the Magento CE 1.9.3 release notes (http://devdocs.magento.com/guides/m1x/ce19-ee114/ce1.9_release-notes.html) that this bug apparently had been fixed in Magento 1.9.3 ("Using a Portable Network Graphics (.png) image on a CMS page no longer results in a HEADERS_ALREADY_SENT message to be logged."). But which file is different in Magento CE 1.9.3? Exactly the one mentioned above:
\app\code\core\Mage\Adminhtml\controllers\Cms\WysiwygController.php
To avoid accidentally overwriting anything, we create a small extension called "Headererror" and use it to extend the CMS controller. First, we create the config.xml:
\app\code\local\Econcess\Headererror\etc\config.xml
which we then populate, for example, as follows:
<config>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Econcess_Headererror before="Mage_Adminhtml">Econcess_Headererror_Adminhtml</Econcess_Headererror>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
After that, the following file is still missing:
\app\code\local\Econcess\Headererror\controllers\Adminhtml\Cms\WysiwygController.php
which we then populate, for example, as follows (based on the corresponding implementation in Magento CE 1.9.3):
<?php
require_once 'Mage/Adminhtml/controllers/Cms/WysiwygController.php';
class Econcess_Headererror_Adminhtml_Cms_WysiwygController extends Mage_Adminhtml_Cms_WysiwygController
{
public function directiveAction()
{
$directive = $this->getRequest()->getParam('___directive');
$directive = Mage::helper('core')->urlDecode($directive);
$url = Mage::getModel('cms/adminhtml_template_filter')->filter($directive);
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();
}
}
We then only need to make Magento aware of the module by creating
\app\etc\modules\Econcess_Headererror.xml
with the following content:
<?xml version="1.0"?>
<config>
<modules>
<Econcess_Headererror>
<active>true</active>
<codePool>local</codePool>
</Econcess_Headererror>
</modules>
</config>
After this, the WYSIWYG editor in the Magento backend can once again be used without any problems and without error messages in the log file. Tested with Magento CE 1.9.2.4.
