Easy debug of Php with ChromePhp and ChromeLogger

Easy debug of Php with ChromePhp and ChromeLogger

 
 

ChromePhp is a Module to log useful details directly in your Chrome JS console. You can inspect most as objects and see infos or values. It is a great way to debug PHP code on the fly, in Google Chrome.

It's very easy to integrate to any project and log any errors, warnings, function outputs, etc. It works in conjunction with Chromelogger, that is an extension for Google Chrome browser. It’s supports lots of languages and platforms : PHP, Python, Ruby, Node.js, .NET, Coldfusion


Important: It is not recommended to enable it on live stage, as it reveal infos you might not want everybody to see, although it's not obvious as it requires the ChromePhp

What we can track with ChromePhp:

- render time
- memory consumption
- cpu usage
- current user infos
- current user roles 
- current user permissions
- current page with all its fields and their value and field settings
- page cache/loaded on request count
- fuel
- modules loaded
- Server vars etc.
- Cookies
- Requests
- mySQL query log


When installed you can also use ChromePhp static methods to output your own data in all your templates or modules:
 


include 'ChromePhp.php';

ChromePhp::log('Hello console!');
ChromePhp::log($_SERVER);
ChromePhp::warn('invisible warning');

 

chromephp

 

Also we can prepend the php file containing the class automatically:

First of all, we will identify include path and we will add ChromePHP there :

/opt/php5.3/bin/php -i | grep include_path
    include_path => .:/opt/php5.3/lib/php => .:/opt/php5.3/lib/php
cd /opt/php5.3/lib/php
mkdir includes 
cd includes 
wget https://raw.github.com/ccampbell/chromephp/master/ChromePhp.php
cd .. 
chmod -R a+rx includes/

And now we will enable automatic prepending of ChromePHP library to every PHP script, which will be executed by PHP :

vim /opt/php5.3/php.ini
auto_prepend_file = /opt/php5.3/lib/php/includes/ChromePhp.php

It uses a little bit of resources, so, if You would like to keep the performance, you could always make a condition by a GET variable or a COOKIE value.

So now, in any of Your scripts You could use ChromePHP to send the debugging data transparently without to disturb others visitors of the site:

Download:



 

 
 

tags: chrome debug php


We use our own cookies and third-party cookies to improve our services, show products based on your preferences, analyse the browsing habits of our users, and enable interaction with social networks. Continuing to browse our sites implies full acceptance of their use. You can change your cookie setting or get more information here: Cookies policy .