3

我发现 ChromePhp 可以帮助我进行 PHP 调试 woahs 并安装了相关的 Chrome 插件,但我似乎无法让它工作。我最初将它放在我重定向的 htdocs 中的一个文件夹中,并使用以下命令将其添加到我在 xampp 的 php.ini 中的 PHP 路径中:

; Windows: "\path1;\path2"
include_path = ".;C:\xampp\php\PEAR;D:\htdocs\includes"

这似乎不起作用,每当我尝试包含文件并输出一个ChromePhp::log("message")

警告:无法修改标头信息 - 标头已由 D:\htdocs\ask.ca\wp-includes\ 中的(输出开始于 D:\htdocs\ask.ca\wp-admin\menu-header.php:91)发送第 385 行的 ChromePhp.php

因此,我在 Windows 路径中尝试了类似的方法,结果相同。

最后我完全进入本地并尝试使用以下方法将 ChromePhp.php 文件包含到我的插件中:

include( dirname(__FILE__) . '/php/ChromePhp.php' );
ChromePhp::log("Hello World");

但我仍然得到同样的错误???任何人都可以解释让 ChromePhp 工作的 ABC 吗?我说 ABC 是因为很明显,即使我阅读了 ChromePhp 的网站说明(以及其他一些人以使其正常工作),这些说明非常简短而且我认为很简单,但我仍然需要更多芝麻街的解释。

4

6 回答 6

5

I'm the developer of ChromePHP. You are seeing this problem because output has already started on the page. As soon as you echo something out you can no longer set headers.

See this related ticket:
https://github.com/ccampbell/chromephp/issues/15

I'm not sure about the internal workings of Wordpress, but basically you have to either log the information before any output has been sent to the page, or you have to use output buffering to prevent output from being sent and then flush the buffer after you are done logging.

Also:
http://wordpress.org/support/topic/error-cannot-modify-header-information-2

于 2012-04-01T02:53:42.387 回答
1

If you can't change your code to get Chrome PHP to work, you can use PHP Console. It works even if output has started. Messages go to Chrome's console and a pop-up. You can configure the pop-up through right-click context menu.

No offense ChromePHP. I also appreciate what people like the authors of ChromePHP and PHP Console are doing.

于 2012-12-03T01:19:33.310 回答
1

如果您只是想在控制台而不是屏幕上调试数据。

// Debug $data will display in console
function console_debug( $data ) {
    $data = json_encode($data);
    echo "<script>console.dir($data)</script>";
}
于 2013-02-26T18:55:37.990 回答
0

我尝试了@Ravs 插件,但我一生都无法让它工作。尽管路径很好,但仍然出现路径错误。

在进入内部并查看网络上的其他评论之后,我采取了稍微冗长的路线,简单地将ChromePhp.php文件放入与文件相同的目录并添加

<?php
ob_start(); 
include 'ChromePhp.php';

...
ChromePhp::log('long winded but it works');
...

ob_flush();
?>
于 2014-10-16T13:32:55.040 回答
0

这对我有用。

在 ChromePhp.php 的第 378 行添加一个 @:

之前->

header(self::HEADER_NAME . ': ' . $this->_encode($data));

之后->

@header(self::HEADER_NAME . ': ' . $this->_encode($data));

于 2013-05-09T23:52:55.033 回答
0

您可以使用基于chromephp的WP Chrome Logger插件。

下载这个插件并激活它。

使用任何函数(示例如下)在 chrome 控制台中输出任何内容(将这些函数放入plugin fileor中functions.php)。

ChromePhp::log('Hello console!');
ChromePhp::log($_SERVER);
ChromePhp::warn('something went wrong!');

用 WP 3.8 测试

于 2013-12-24T13:42:55.247 回答