ccampbell/chromelogger

ChromePhp stops logging during code block but code block continues to execute

jasoncatudal opened this issue · 1 comments

Hi there,

Here's my code. The third log command doesn't appear nor any further log commands, but the code executes to the bottom of the block. In other words, the last echo appears but not the Chrome Logger logs in between. What am I missing?

log('Hello console!'); $mysqli = new mysqli("localhost", "username", "password", "database", 8889); $log->log("Mysqli created"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: " . $mysqli->connect_error; } echo $mysqli->host_info . "\n"; $log->log("after host info"); ChromePhp::log("setup"); $query = "SELECT \* FROM products"; ChromePhp::log($query); echo $query; ?>

EDIT: I should point out that I realize this might be hard to test. When I run this code on my machine, the database connection doesn't trigger any errors so it looks like that is good. However, the query execution doesn't seem to be working right. I don't know why (which is why I'm debugging!). If I ever figure it out, I'll update this post so we can try to figure out what's going on here with ChromePhp and why it doesn't log the lines before the query execution. Also, this is using MAMP on Mac OS X in case you would like to connect to your own db to try it.

The 'problem' is your code, not ChromePhp/ChromeLogger. ChromeLogger depends on HTTP headers to do it's work. The minute you do an 'echo' statement, headers send, so any ChromePhp calls you make after output has started will not make it to chrome.

You can try starting output buffering at the top of your code (ob_start()) and that may solve your problem.