Debugging PHP Using Chrome Console Tab Like JavaScript

If you are a PHP developer and want debugging PHP code like you do your JavaScript code i.e. using console.log() function and see the result in the Console tab of your Chrome then keep reading this post, it’s specially for you.

Here are the few simple steps to follow:

1. Installing “Chrome Logger” Extension

First of all you need to install the Chrome Logger extension in your Chrome browser. To install the extension click here and add the to your Chrome browser.

2. Installing ChromePHP Library for “Chrome Logger”

Get the ChromePhp.php file from here. Include the file in your project by using autoloader or inlcude_once() feel free to use the method you like.

Note: If you want to use it with Laravel, simply keep the file in your helper or lib directory (the directory where you keep your own helper classes or functions) and all is done.

3. Get Ready and Use:

You’ll see an icon on the top right of your Chrome browser like ‘cmd’ icon for Window. Click this icon to activate, it will lighten up blue. Now, you are ready to log your variables or whatever you want in the Console tab of your Chrome browser. Here are a couple of examples:

838-2

ChromePhp::log('Hello console log');

ChromePhp::info('Hello console info');

ChromePhp::warn('Hello console warn');

 

Note: You can also write your logs to Console tab of Chrome no matter what language you are using. This post was for PHP but you can use it using Perl, Python, Ruby, Jave, .Net and other languages as well. Follow instructions on the link and enjoy easy debugging using Console tab of Chrome. 

Leave a Reply

Your email address will not be published. Required fields are marked *