Debugging Magento调试标头已发送错误
我在system.log文件中收到以下错误:Debugging Magento调试标头已发送错误,debugging,magento,header,Debugging,Magento,Header,我在system.log文件中收到以下错误: 2011-01-12T14:16:52+00:00 DEBUG (7): HEADERS ALREADY SENT: [0] C:\xampp\htdocs\www.mysite.com\app\code\core\Mage\Core\Controller\Response\Http.php:44 [1] C:\xampp\htdocs\www.mysite.com\lib\Zend\Controller\Response\Abstract.
2011-01-12T14:16:52+00:00 DEBUG (7): HEADERS ALREADY SENT:
[0] C:\xampp\htdocs\www.mysite.com\app\code\core\Mage\Core\Controller\Response\Http.php:44
[1] C:\xampp\htdocs\www.mysite.com\lib\Zend\Controller\Response\Abstract.php:727
[2] C:\xampp\htdocs\www.mysite.com\app\code\core\Mage\Core\Controller\Response\Http.php:75
[3] C:\xampp\htdocs\www.mysite.com\app\code\core\Mage\Core\Controller\Varien\Front.php:188
[4] C:\xampp\htdocs\www.mysite.com\app\code\core\Mage\Core\Model\App.php:304
[5] C:\xampp\htdocs\www.mysite.com\app\Mage.php:596
[6] C:\xampp\htdocs\www.mysite.com\index.php:81
我知道“headers ready sent”是什么意思,但我不知道是什么文件导致了这种情况,跟踪也没有真正给我任何信息
有没有办法找出有问题的文件
谢谢 我也看到了。我认为这与所见即所得的图像有关。在浏览管理员(尤其是CMS页面)时,尝试查看日志,您可能会看到它发生。这是无害的。这是一条艰难的道路 在执行日志记录的文件中查找位置
C:\xampp\htdocs\www.mysite.com\app\code\core\Mage\Core\Controller\Response\Http.php
Mage::log('HEADERS ALREADY SENT: '.mageDebugBacktrace(true, true, true));
添加日志记录以获取到目前为止包含/需要的每个文件的副本
Mage::log(print_r(get_included_files(),true));
如果您记得将文件恢复到预处理状态,则可以将此日志直接添加到核心文件中,或者可以在以下位置添加临时副本:
app/code/local/Mage/Core/Controller/Response/Http.php
只要您记住在完成时删除它(或者只使用git)
检查此文件列表中常见的空白可疑文件,然后检查它们是否有可能产生输出的任何函数(echo
,print
,readfile
,可能还有更多)这里有一个更简单的方法
查看文件中的canSendHeaders
方法
lib/Zend/Controller/Response/Abstract.php
添加一些日志到
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, null, 'exception.log', true);
Mage::log('Line: ' . $line, null, '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;
}
当我以“黑客”的方式构建Ajax请求时,我收到了这个错误,直接回显内容,而不是通过布局发送内容。一旦我通过布局发送了它们,错误就消失了。请看我自己的问题:
感谢@alan对我问题的回答。我想这可能是
OnePageCheckout
扩展问题。我在Magento中也有同样的错误,而且这个错误似乎并不流行。我还安装了OnePageCheckout
。但是,当然,这可能只是巧合。也许这会对某人有所帮助:
当我在CMS->pages中编辑页面时打开Magento的WYSIWYG时,我会收到类似的消息(默认情况下,我禁用了WYSIWYG,因此我必须单击“显示/隐藏编辑器”才能启用它)。如果页面包含CMS标记,例如:
{{store url='my-other-page'}}
单击“显示/隐藏编辑器”后,system.log中将显示此消息:
2013-04-06T11:10:38+00:00调试(7):已发送的标题:[0]…\app\code\core\Mage\core\Controller\Response\Http.php:52
echo $string;
[1] …\lib\Zend\Controller\Response\Abstract.php:766
[2] …\app\code\core\Mage\core\Controller\Response\Http.php:83
[3] …\app\code\core\Mage\core\Controller\Varien\Front.php:188
[4] …\app\code\core\Mage\core\Model\app.php:354
[5] …\app\Mage.php:683
[6] …\index.php:87
在Magento中,最常见的情况是直接从控制器输出内容
而不是做
$this->getResponse()->setBody($string);
在控制器内,执行以下操作:
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);
}
return !$ok;
}
在进行Ajax调用时遇到同样的问题 当我进行Ajax调用并直接从controller调用模板时,我正在获取日志
当我更改代码并在布局xml文件中创建块时。日志错误已修复。该错误是从Mage\u Core\u Controller\u Response\u Http->sendHeaders()引发的。此函数调用实际执行检查以查看是否已发送头的超类函数Zend\u Controller\u Response\u Abstract->canSendHeaders() Zend_Controller_Response_抽象类处理发送响应头和跟踪头上次发送的时间(以及从哪个文件和行发送)。下面是该函数的外观,我们将第316行更改为lib\Zend\Controller\Response\Abstract.php:
public function canSendHeaders($throw = false)
{
$ok = headers_sent($file, $line);
if ($ok) {
Mage::log('Cannot send headers; headers already sent in ' . $file . ', line ' . $line, null, 'headers.log');
}
return !$ok;
#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;
}
致:
这将在/var/log/header.log中记录错误。我在安装Magento时也遇到同样的问题 在我的例子中,在PHP中启用输出缓冲解决了这个问题 在使用PHP5.6的xampp中,默认情况下会启用输出缓冲
在使用PHP5.3的xampp中,默认情况下禁用输出缓冲。在我们的例子中,这是Magento CE 1.9.2.4中的一个错误,在Magento CE 1.9.3中修复了该错误,在使用图像时发生了所见即所得。我们刚刚做了一个小扩展,它覆盖了\app\code\core\Mage\Adminhtml\controllers\Cms\WysiwygController.php中的函数directiveAction()。有关更多详细信息,请参阅(德语)。谢谢您的回复。这实际上发生在所有前端页面视图上。我的任务是得到一个干净的system.log文件!然后,您应该开始寻找空白output@clockworkgeek,我也犯了同样的错误,但我想复制这个,我已经通过echo直接在块、控制器、结束标记和空格上完成了,但还没有复制。如何复制此警告?你知道怎么做吗?在CMS页面的WYSIWIG编辑器中删除html元素之间的空白(如@Anton所建议的)消除了OP问题中的警告。注意:打开CMS页面的所见即所得编辑器似乎会插入空格。每次我在CMS中打开所见即所得编辑器(即使只是为了查看html),我必须确保删除空白。。。Magento的另一个恼人的功能。这就是我想要的。谢谢。我将努力完成这份清单,并将在几年后完成后在这里汇报。谢谢对于Alan Storm,你能给我一个复制此警告的示例吗?我尝试使用带有空格的关闭php标记
?>
,但没有运气下面的方法更好,这应该是公认的答案这只记录了3行空行:2011-01-13T09:59:41+00:00 EMERG(0):这不是Mage::log
的正确语法。我会把这归因于艾伦很累,这肯定不是他的典型特征。如果对Mage::log
使用多个参数,则第二个参数是错误级别,需要第三个参数来指示日志文件。这里您真正想要的是Mage::log(“file:$file,line:$line”)
@BrianVPS谢谢您的提醒--我确实有“DERP'd”
public function canSendHeaders($throw = false)
{
$ok = headers_sent($file, $line);
if ($ok) {
Mage::log('Cannot send headers; headers already sent in ' . $file . ', line ' . $line, null, 'headers.log');
}
return !$ok;
#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;
}