OpenMage / magento-lts

Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.
https://www.openmage.org
Open Software License 3.0
870 stars 436 forks source link

Headers already sent 1.9.3.x #246

Closed seansan closed 6 years ago

seansan commented 7 years ago

Hi, I was just trying M 1.9.3.x version. Have been running on stable 1.9.3.1. And I must admit we had this debug message before. HEADERS ALREADY SENT - and we did fix it.

Only after the upgrade to 1.9.3.x it is back

Maybe some others have encountered this too? (we have log enabled ;)

If/when I find a fix I will post it

2017-03-19T16:17:07+00:00 DEBUG (7): HEADERS ALREADY SENT:

[0] /app/code/core/Mage/Core/Controller/Response/Http.php:52
[1] /lib/Zend/Controller/Response/Abstract.php:768
[2] /app/code/core/Mage/Core/Controller/Response/Http.php:84
[3] /app/code/core/Mage/Core/Controller/Varien/Front.php:184
[4] /app/code/core/Mage/Core/Model/App.php:365
[5] /app/Mage.php:683
[6] /index.php:104

sreichel commented 7 years ago

In Zend_Controller_Response_Abstract you can change canSendHeaders method to log file and line:

    public function canSendHeaders($throw = false)
    {
        $ok = headers_sent($file, $line);
        if ($ok && $throw && $this->headersSentThrowsException) {
            #require_once 'Zend/Controller/Response/Exception.php';
            throw new Zend_Controller_Response_Exception('Cannot send headers; headers already sent in ' . $file . ', line ' . $line);
        }
        // to get PHP's report on which file is sending a header.
        if ($ok){
            Mage::log('File: ' . $file);
            Mage::log('Line: ' . $line);
        }
        return !$ok;
    }
seansan commented 7 years ago

thanks yes we have added debugging (actually on more levels) But does this not show the same output like some lines higher ('Cannot send headers; headers already sent in ' . $file . ', line ' . $line);

Or is the idea here to get a list of files and once we hit the error, we take the line just before it?

On Mon, Mar 20, 2017 at 12:16 PM, sreichel notifications@github.com wrote:

In Zend_Controller_Response_Abstract you can change canSendHeaders method to log file and line:

public function canSendHeaders($throw = false)
{
    $ok = headers_sent($file, $line);
    if ($ok && $throw && $this->headersSentThrowsException) {
        #require_once 'Zend/Controller/Response/Exception.php';
        throw new Zend_Controller_Response_Exception('Cannot send headers; headers already sent in ' . $file . ', line ' . $line);
    }
    // to get PHP's report on which file is sending a header.
    if ($ok){
        Mage::log('File: ' . $file);
        Mage::log('Line: ' . $line);
    }
    return !$ok;
}

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/OpenMage/magento-lts/issues/246#issuecomment-287732052, or mute the thread https://github.com/notifications/unsubscribe-auth/AAn0a-PFYTEM3FGQhdqfbS4W6w1cjGAhks5rnmAZgaJpZM4MhygJ .

seansan commented 7 years ago

lib/Zend/Controller/Response/Abstract.php: Line: 593

Where the bodyb is outputted ;)

<!doctype html> seems right everywhere

sreichel commented 6 years ago

Not really related to LTS.

seansan commented 6 years ago

I have added some more debug statements

can it be smart to add the code to LTS? but escape it?

Below has helped us a lot identifying where it is coming from

`    public function canSendHeaders($throw = false)
    {
        $ok = headers_sent($file, $line);
        // to get PHP's report on which file is sending a header.
        if ($ok !== false){
            Mage::log('File: ' . $file . ' // Line: ' . $line, null, 'httpheaderssent_exception.log', true);
            $module = Mage::app()->getRequest()->getModuleName();
            $controller = Mage::app()->getRequest()->getControllerName();
            $action = Mage::app()->getRequest()->getActionName();
            Mage::log('Url: ' . $module . '/' . $controller . '/' . $action, null, 'httpheaderssent_exception.log', true);
            $body = implode('', $this->_body);
            $body = substr($body, 0, 1000);
            Mage::log('Body: ' . $body, null, 'httpheaderssent_exception.log', true);
        }
        if ($ok && $throw && $this->headersSentThrowsException) {
            #require_once 'Zend/Controller/Response/Exception.php';
            throw new Zend_Controller_Response_Exception('Cannot send headers; headers already sent in ' . $file . ', line ' . $line);
        }

        return !$ok;
    }`