Categories
Programming

Improving PHP Xdebug Speed

Great, you have finally figured out how to install and enable PHP Xdebug. Now you can debug your PHP websites and web apps in your local machine. However what you might found out is that after enabling Xdebug, your website’s response time is very low. You might have to wait for more like a second to display your website.

Disabling profiler

As I found out, the main reason for this is the Xdebug profiler. If Xdeubg profiler is enabled, it will add some significant overhead to the PHP execution. Profiling enables us to get execution statistics such as name of functions executed, the number of times a function has called, execution time etc. This can give information on how to improve the code.

For general debugging, profiling is not needed. So we can disable it by updating the php.ini file and restart the server. Now your web application response time should be greatly improved.

xdebug.profiler_enable = 0;

Well if you want to enable it again, you can set the value to ‘1’ and restart the server. Another way is to use the profiler_enable_trigger cookie. For this first we need to specify value for it.

xdebug.profiler_enable_trigger = 1;

Now to enable profiler for an app request, you need to have the Xdebug profiler cookie set to this value. In Firefox Developer Edition, I use The Easiest Xdebug add on to do this. With this addon, I can easily specify the profiler_enable_trigger value and then before request the website, I would click a button to set the cookie value.

Setting remote host to 127.0.0.1

Typically you would put localhost as the xdebug.remote_host, but I found out that there is a slight lag in Windows when referring localhost to 127.0.0.1. So replace localhost to 127.0.0.1. The special IP 127.0.0.1 is referring to the current machine you are using.
xdebug.remote_host=127.0.0.1

Additional References

PHP Applications Profiling in PhpStorm: https://www.youtube.com/watch?v=_ua_O01IICg

Xdebug Documentation basic features: http://xdebug.org/docs/basic

Firefox : The easiest Xdebug: https://addons.mozilla.org/en-us/firefox/addon/the-easiest-xdebug/

 

Categories
Programming

Setting up xdebug with phpstorm

This guide provide a step by step details on how to set up phpstorm IDE to work with xdebug.

 

Installing on Ubuntu

In software search for xdebug and install.

 

Add to the following xdebug settings to php.ini file

 

xdebug.remote_enable = 1
xdebug.remote_port = 9000
xdebug.remote_handler = dbgp
xdebug.remote_mode = req

 

 

 

Installing on Windows XAMPP

First download xdebug and copy it into the extension folder. Copy the full path the extension.

 

Add the following xdebug settings to php.ini file.

php.ini file

[XDebug]
zend_extension = "C:xamppphpextphp_xdebug-2.2.5-5.5-vc11.dll"
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_log="c:tmpxdebugxdebug.log"
xdebug.show_exception_trace=0
xdebug.show_local_vars=9
xdebug.show_mem_delta=0
xdebug.trace_format=0
xdebug.profiler_enable = 1
xdebug.profiler_output_dir ="c:tmpxdebug"

 

 

 

 

Install easiest xdebug for Firefox and specify the remote IDE key for Firefox

easiest_xdebug_ff

 

Then in the xdebug configuration apply following

phpstorm_xdebug

 

 

Put debug points and run the remote debug setting.

xdebug_option

 

 

enable the easiest debug and navigate the test page through the browser. Your debug point should be hit, the request url is reading the debug file.

 

Notes:

To stop breaking at the first line Untick Run->break and first lineā€¦