Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a interactive debugger for php like ruby's debugger?

I watched the Creating a weblog in 15 minutes with Rails 2 and after 9 minutes in the video he shows ruby's interactive debugger, which allows you to call functions/methods from within a running script.

This goes way beyond breakpoints and looks very useful.

Is there something for PHP that gives similar functionality?

like image 775
Bob Fanger Avatar asked Feb 22 '09 14:02

Bob Fanger


2 Answers

Install xdebug and then use one of the debug clients mentioned here.

like image 176
Milen A. Radev Avatar answered Oct 20 '22 15:10

Milen A. Radev


Although Milen's answer is the only correct one circa 2009, and Xdebug is still a useful tool, using it requires you to recompile your PHP or to edit your php.ini runtime configuration to load it as a shared object. It also means using a specific client application that supports its network protocol, such as an IDE like PhpStorm.

An alternative is phpdbg, which is an interactive debugger that ships with PHP core versions 5.6 and later and can debug PHP scripts written to conform to PHP 5.4 or later.

Using it is simple:

phpdbg php_script_i_want_to_debug.php

Once in the debugger, type help to access the help menu.

If you don't already have phpdbg on your system, it may be because your PHP was configured without the --enable-phpdbg option. You can either:

  1. Recompile your PHP, being sure to add --enable-phpdbg when you run ./configure (this will simply also build the phpdbg binary), or
  2. download the phpdbg source independently and compile it against your installed PHP (assuming you have the PHP source available). Instructions for doing that, while sparse, are here.
like image 22
M12 Avatar answered Oct 20 '22 15:10

M12