See How PHP Web Application Work With XDebug

The most common issue when we are developing web applications using PHP is the debugger. Debugging our web application is very important when we are developing and testing our project. Usually I’m using var_dump(), print_r(), or echo to show the output of the variable or the result. The alternative is using Zend Studio, the PHP IDE (Integrated Development Environment), but it is too expensive and I couldn’t afford it now.

So the alternative to see how your web application works is using XDebug. XDebug is a PHP extension for debugging and profiling. It supports stack and function traces, profiling information and memory allocation, and script execution analysis. And it is free to use.

XAMPP for Windows already includes XDebug in it, but it is not yet enabled.

To enable it just open the php.ini and enable:

zend_extension = "pathtophpextphp_xdebug.dll"

To install XDebug on Linux, you can use pecl:

pecl install xdebug

How to use XDebug:

1. Auto trace mode:
XDebug has auto trace mode, you can enable it in php.ini:

xdebug.auto_trace=On
xdebug.trace_output_dir=c:data

In this mode, XDebug will write the log into c:data for every PHP code run.

2. Manually add XDebug for tracing part of code:
When you need to trace part of your code you can manually add XDebug code, so you can have the trace result:

 xdebug_start_trace('c:/data/fac.xt');

 //Bunch php code here

  xdebug_stop_trace();

With XDebug we can find where our code goes wrong and fix it. It is a pretty handy tool to increase your productivity and produce fewer bugs in your web application.

More info:
XDebug
Introducing Xdebug – Zend article