3

I found ChromePhp to help with my PHP debugging woahs and installed the related Chrome plugin but I can't seem to get it to work. I originally put it in a folder in my redirected htdocs and added that to my PHP path in php.ini of xampp using:

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

That didn't seem to work I kept getting errors like the one below whenever I tried to include the file and output a ChromePhp::log("message")

Warning: Cannot modify header information - headers already sent by (output started at D:\htdocs\ask.ca\wp-admin\menu-header.php:91) in D:\htdocs\ask.ca\wp-includes\ChromePhp.php on line 385

So then I tried a similar approach in my windows path, with the same result.

Finally I went completely local and tried to include the ChromePhp.php file into my plugin using:

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

But I still get the same error??? Can anyone explain the ABC's of getting ChromePhp to work? I say ABC's since apparently even though I read ChromePhp's website instructions (and couple other peoples in order to get this to work) which are very short and I thought simple, I still need a more Sesame Street explanation.

Machavity
  • 30,841
  • 27
  • 92
  • 100
mtpultz
  • 17,267
  • 22
  • 122
  • 201

6 Answers6

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

Craig
  • 2,684
  • 27
  • 20
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.

Skurfur
  • 375
  • 2
  • 8
1

If you're just looking to debug data in the console rather than on screen.

// Debug $data will display in console
function console_debug( $data ) {
    $data = json_encode($data);
    echo "<script>console.dir($data)</script>";
}
  • I actually came to the original post to figure out how to fix the same issue I was having, but unfortunately none of the proposed solutions worked for me. This post, did however give me an idea to a proposed solution that fit my own needs of just returning the output of variables and objects using console.log instead. – Mike Kormendy Dec 01 '14 at 05:55
  • This is a pretty good solution for simple testing, nice stuff! – Rohan Deshpande Feb 28 '15 at 00:44
0

this worked for me.

Add a @ in line 378 in ChromePhp.php:

Before->

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

After ->

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

Angelinux
  • 144
  • 4
  • 9
  • This won't work quite as intended. For me it just hides any errors and doesn't output anything to the console regardless. – Mike Kormendy Dec 01 '14 at 05:41
0

You can use WP Chrome Logger plugin, which is based on chromephp.

Download this plugin and activate it.

Use any function ( below in example ) to output anything in chrome console ( put these functions in plugin file or functions.php ).

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

Tested with WP 3.8

Ravinder Kumar
  • 399
  • 4
  • 16
0

I tried @Ravs plugin but could not for the life of me get it to work. Kept getting path errors despite the fact the path was fine.

After peaking inside and looking at other comments on the web, I took the slightly more long winded route of simply throwing ChromePhp.php into the same directory as the file and adding

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

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

ob_flush();
?>
myol
  • 8,857
  • 19
  • 82
  • 143