Magento 调试标头已发送错误
我在我的 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.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
我知道“标头已发送”的含义,但我不知道是什么文件导致了此错误,并且跟踪并没有真正为我提供任何信息。
有没有办法找出有问题的文件?
谢谢!
I am receiving the following error in my system.log file:
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
I know what "headers already sent" means but I have no idea what file is causing this and the trace doesn't really give me any information.
Is there a way of finding out the offending file?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
这是困难的方法。
查找正在执行日志记录的文件中的位置
添加日志记录以获取迄今为止包含/所需的每个文件的副本
如果您记得将文件恢复到预先混乱的状态,则可以将此日志记录直接添加到核心文件中,或者您可以添加一个临时副本,
只要你记得在完成后删除它(或者只使用 git)。
检查此文件列表中是否有常见的空格嫌疑,然后检查它们是否有可能产生输出的任何函数(
echo
、print
、readfile
,可能还有更多)Here's the hard way.
Find the location in the file that's doing the logging
Add logging to get a copy of every file included/required so far
You can add this logging directly to the core file if you remember to restore the file to it's pre messed with condition, or you can add a temporary copy at
as long as you remember to remove it when you're done (or just use git).
Check this list of files for the usual white-space suspects, and then check them for any functions that might produce output (
echo
,print
,readfile
, there's probably more)这是一个更简单的方法。
查看文件中的
canSendHeaders
方法添加一些日志记录
Here's an easier way.
Look at the
canSendHeaders
method in fileAdd some logging to
该错误是从 Mage_Core_Controller_Response_Http -> 引发的发送标头()。该函数调用超类函数,该函数实际上执行检查以查看标头是否已发送,Zend_Controller_Response_Abstract -> canSendHeaders()。
Zend_Controller_Response_Abstract 类处理发送响应标头和跟踪上次发送标头的时间(以及从哪个文件和行)。该函数如下所示,我们将在第 316 行对 lib\Zend\Controller\Response\Abstract.php 进行更改:
收件人:
这会将错误记录在 /var/log/header.log 中。
That error is thrown from Mage_Core_Controller_Response_Http -> sendHeaders(). This function calls the super class function that actually does the check to see whether or not headers have already been sent, Zend_Controller_Response_Abstract -> canSendHeaders().
The Zend_Controller_Response_Abstract class handles, among other things, sending response headers and tracking the last time the headers were sent (and from what file and line). Here is what that function looks like, and where we'll make a change around line 316 to lib\Zend\Controller\Response\Abstract.php:
To:
This will log the error in /var/log/header.log.
在 Magento 中最常见的情况是直接从控制器输出内容。
不要
在控制器中执行此操作,而是执行以下操作:
The most common place you run into this in Magento is when you output content directly from the controller.
Instead of doing
within a controller, do this:
我也看到这个。我认为这与所见即所得的图像有关。尝试在浏览管理(尤其是 CMS 页面)时查看日志,您可能会看到这种情况发生。这是无害的。
I see this too. I think it has something to do with images in WYSIWYG. Try watching the logs whilst going through the admin (especially CMS pages) and you might see it happen. It's harmless.
也许这对某人有帮助:
当我在 CMS 中编辑页面时打开 Magento 的 WYSIWYG 时,我收到类似的消息 ->页面(默认情况下我禁用了所见即所得,因此我必须单击“显示/隐藏编辑器”才能启用它)。如果页面包含 CMS 标签,例如:
单击“显示/隐藏编辑器”后,此消息会出现在 system.log 中:
Maybe it will be helpful for someone:
I get similar message when I turn on Magento's WYSIWYG when editing pages in CMS -> Pages (I've got WYSIWYG disabled by default so I have to click "Show/Hide Editor" in order to enable it). If page contains CMS tags such as for example:
this message apears in the system.log after I click "Show/Hide Editor":
当我以一种“hacky”方式构建我的 Ajax 请求时,我收到了这个错误,直接回显内容而不是通过布局发送它们。一旦我通过布局将它们发送出去,错误就消失了。在这里查看我自己的问题:
最佳输出方式来自 Magento 管理扩展的 ajax 数据
向 @alan 提供他对我的问题的回答。
I received this error when I built my Ajax request in a "hacky" way, echoing the contents directly instead of sending them out through the layout. Once I sent them out through the layout, the errors disappeared. See my own question here:
Best way to output ajax data from a Magento Admin Extension
props to @alan for his answer to my question.
我认为这可能是
OnePageCheckout
扩展问题。我在 Magento 中也有同样的错误,而且似乎这个错误并不那么流行。我还安装了OnePageCheckout
。但是,当然,这可能只是巧合。I think this might be
OnePageCheckout
extension problem. I have the same error in Magento, and seems that this error is not so popular. Also I haveOnePageCheckout
installed. But, of course, this might be just coincidence.进行 Ajax 调用时出现相同问题
当我进行 Ajax 调用并直接从控制器调用模板时,我收到了日志。
当我更改代码并在布局 xml 文件中创建块时。日志错误已修复。
Same Issue while making Ajax Call
I was getting the Log when i was making Ajax call and calling the template directly from controller.
When i changed the code and created block in layout xml file. the log error got fixed.
我在安装 Magento 时遇到同样的问题。
就我而言,在 PHP 中启用 output_buffering 解决了这个问题。
在 PHP 5.6 的 xampp 中,默认启用 output_buffering。
在 PHP 5.3 的 xampp 中,output_buffering 默认情况下处于禁用状态。
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.
在我们的例子中,这是 Magento CE 1.9.2.4 中的一个错误,该错误已在 Magento CE 1.9.3 中修复,在使用 WYSIWYG 处理图像时发生。我们刚刚做了一个小扩展,它覆盖了 \app\code\core\Mage\Adminhtml\controllers\Cms\WysiwygController.php 中的函数directiveAction()。有关更多详细信息,请参阅(德语)这里。
In our case this was a bug in Magento CE 1.9.2.4, which was fixed in Magento CE 1.9.3, happened when using WYSIWYG with images. We just made a little extension which overwrites the function directiveAction() in \app\code\core\Mage\Adminhtml\controllers\Cms\WysiwygController.php. For more Details see (in German) here.