Debugging PHPAbout the debugger
PHP 3 includes support for a network-based debugger.
PHP 4 does not have an internal debugging facility.
You can use one of the external debuggers though. The
Zend IDE includes
a debugger, and there are also some free debugger extensions
like DBG at &url.dbg;, the
Advanced PHP Debugger (APD) or
Xdebug which even has a compatible
debugger interface as PHP 3's debugging functionality as is described
in this section.
Using the Debugger
The internal debugger in PHP 3 is useful for tracking down
evasive bugs. The debugger works by connecting to a
TCP port for every time PHP 3 starts up.
All error messages from that request will be sent to this
TCP connection. This information is intended for
"debugging server" that can run inside an
IDE or programmable editor (such as Emacs).
How to set up the debugger:
Set up a TCP port for the debugger in the configuration file (debugger.port) and enable it
(debugger.enabled).
Set up a TCP listener on that port somewhere (for example
socket -l -s 1400 on Unix systems).
In your code, run
"debugger_on(host)", where
host is the IP number or name of the
host running the TCP listener.
Now, all warnings, notices etc. will show up on that listener
socket, even if you turned them off with
error_reporting.
Debugger Protocol
The PHP 3 debugger protocol is line-based. Each line has a
type, and several lines compose a
message. Each message starts with a line of
the type start and terminates with a line of
the type end. PHP 3 may send lines for different
messages simultaneously.
A line has this format:
date
Date in ISO 8601 format
(yyyy-mm-dd)
timeTime including microseconds:
hh:mm:uuuuuuhost
DNS name or IP address of the host where the script error was
generated.
pid
PID (process id) on host of the
process with the PHP 3 script that generated this error.
type
Type of line. Tells the receiving program about what it
should treat the following data as:
Debugger Line TypesNameMeaningstart
Tells the receiving program that a debugger message
starts here. The contents of
data will be the type of error
message, listed below.
messageThe PHP 3 error message.location
File name and line number where the error occurred. The
first location line will always
contain the top-level location.
data will contain
file:line.
There will always be a location line
after message and after every
function.
framesNumber of frames
in the following stack dump. If there are four frames,
expect information about four levels of called functions.
If no "frames" line is given, the depth should be assumed
to be 0 (the error occurred at top-level).
function
Name of function where the error occurred. Will be
repeated once for every level in the function call
stack.
end
Tells the receiving program that a debugger message ends
here.