mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-13 17:23:58 +02:00
47 lines
2.0 KiB
Markdown
47 lines
2.0 KiB
Markdown
---
|
|
title: Xdebug
|
|
isChild: true
|
|
anchor: 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][xdebug-install] 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 IDEs have built-in or plugin-based support for graphical debugging with Xdebug. MacGDBp is a free, open-source,
|
|
stand-alone Xdebug GUI for macOS.
|
|
|
|
* [Learn more about Xdebug][xdebug-docs]
|
|
* [Learn more about MacGDBp][macgdbp-install]
|
|
|
|
|
|
[xdebug-install]: https://xdebug.org/docs/install
|
|
[xdebug-docs]: https://xdebug.org/docs/
|
|
[macgdbp-install]: https://www.bluestatic.org/software/macgdbp/
|