Bob Fanger
Bob Fanger

Reputation: 29897

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?

Upvotes: 10

Views: 2403

Answers (2)

M12
M12

Reputation: 857

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.

Upvotes: 3

Milen A. Radev
Milen A. Radev

Reputation: 62583

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

Upvotes: 9

Related Questions