Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 1.98 KB

03-06-01-XDebug.md

File metadata and controls

46 lines (33 loc) · 1.98 KB
title isChild anchor
Xdebug
true
xdebug

Xdebug {#xdebug_title}

One of the most useful tools in software development is a proper debugger. It allows you to trace the execution of your code and monitor the contents of the stack. Xdebug, PHP's debugger, can be utilized by various IDEs to provide Breakpoints and stack inspection. It can also allow tools like PHPUnit and KCacheGrind to perform code coverage analysis and code profiling.

If you find yourself in a bind, willing to resort to var_dump()/print_r(), and you still can't find the solution - maybe you need to use the debugger.

Installing Xdebug can be tricky, but one of its most important features is "Remote Debugging" - if you develop code locally and then test it inside a VM or on another server, Remote Debugging is the feature that you will want to enable right away.

Traditionally, you will modify your Apache VHost or .htaccess file with these values:

{% highlight ini %} php_value xdebug.remote_host=192.168.?.? php_value xdebug.remote_port=9000 {% endhighlight %}

The "remote host" and "remote port" will correspond to your local computer and the port that you configure your IDE to listen on. Then it's just a matter of putting your IDE into "listen for connections" mode, and loading the URL:

http://your-website.example.com/index.php?XDEBUG_SESSION_START=1

Your IDE will now intercept the current state as the script executes, allowing you to set breakpoints and probe the values in memory.

Graphical debuggers make it very easy to step through code, inspect variables, and eval code against the live runtime. Many IDE's have built-in or plugin-based support for graphical debugging with Xdebug. MacGDBp is a free, open-source, stand-alone Xdebug GUI for Mac.