2. Who Is This Guy?
Bryce Embry
Application Developer at
Vanderbilt University Medical Center
Devoted user of Opera web browser
Ambivalent user of Windows Desktop
Handyman, cook, hobbyist musician, husband, & father
3. In this session…
▪ What is xdebug?
▪ Getting Started
▪ Tracing
▪ Profiling
▪ Debugging
▪ Debug Demo
8. Code Coverage
Identify which lines of a
script have been
executed during a
request.
This feature is used by
other programs to create
test coverage reports
14. Client: URL Triggers
To trigger xdebug, need to use a cookie or add parameters to
the URL.
Doing this by hand violates the programming principle, “Work hard
to be lazy”.
15. Client: Bookmarklets
PHPStorm has a site to create
“bookmarklets” to add trigger
parameters to your URL.
https://www.jetbrains.com/phpstorm/marklets/
22. Configuration Options
trace_enable_trigger Turn “on” to allow traces
trace_enable_trigger_valu
e
Sets a passcode that must be passed by browser to start a trace
trace_format Sets the output format for a trace as human-readable, machine readable, or HTML
trace_options Turn “on” to have trace data appended to a file instead of creating new file.
trace_output_dir Sets directory where trace file will be saved.
Make sure this directory is readable by the PHP process (ie Apache)
If using HTML output, set this as a web-accessible directory
trace_output_name Sets name for trace file. The extension “.xt” will be appended by default.
Can include variables such as:
%t = timestamp %R = $_SERVER[‘REQUEST_URI’]
28. Configuration Options
profiler_append Turn “on” to have data appended to existing file instead of creating a new file.
profiler_enable Turn “on” if you want constant profiling. (Hint: You don’t.)
profiler_enable_trigger Turn “on” to allow profiling to be activated by a browser trigger
profiler_enable_trigger_valu
e
Sets a passcode that must be passed by browser to start a profile
profiler_output_dir Sets directory where profile file will be saved.
Make sure this directory is readable by the PHP process (ie Apache)
profiler_output_name Sets name for profile file.
Can include variables such as:
%t = timestamp %s = script name
31. How debugging works
Web server IDE & Browser
http request / 80
dbgp / 9000
http response / 80
32. Debugging with xdebug
1. Set pause
point in code
2. Turn
on
listening
in IDE
3. Enable
debug in
browser
5. Walk through
code in the IDE
as it is executed
4. Load page
in browser
34. Configuration Options
remote_enable Turn “on” to enable debugging
Remote_host Set the host name or IP address of the debugging client computer.
Can only have one value, so good way to lock down xdebug to only one user.
Remote_connect_back Turn “on” to ignore the remote_host setting and connect back to any xdebug
client. Useful if multiple developers are running from same debug server.
Remote_port Set the port xdebug uses for communication. Default is 9000.
Remote_mode Set to “req” to connect to debug client when code begins.
Set to “jit” to connect to debut client only on failure.
35. Tip: Map your code
If you have two
copies of code (local
and server), make
sure they are mapped
in the IDE and in-
sync. Otherwise,
xdebug will lie to you.
36. Tip: Debugging is one-way
Once you’ve passed
a point in code,
you can’t go back.
Talk spurred by Jim – struggling to use xdebug.
Now, hooked on xdebug and wouldn’t want to work without it.
Theme: xdebug is like light in code
Past lives – teacher, IT support manager, Director of IT
Programmer 10 months – long enough for a baby, but not enough to understand parenthood
Opera – UI (tabs, speed dial, etc.), Coast for iPad, Bork Bork 2003.
Five features, will cover 2.5
One concept, five tools.
Concept = document running code
Trace helps with new code base. How does the first page load (5,000 function calls in framework)
In unfamiliar framework, see pre-loaded global values
Required tool to generate code coverage reports (that’s how we started)
Note: Green and red are just CSS settings
Didn’t realize these tracebacks were special at first.
Summary: Race, Profile, Debug, Coverage, Traceback
Now, how to install
Our dev server managed by sys admin behind firewall. Messy setup.
Local xampp, not so tough.
Cool tool, though not entirely accurate.
Note: zend_extension, not just “extension”
Need to communicate with xdebug to run scripts. Here’s how.
Bookmarklets don’t show “on” vs “off”
Chrome works on Opera. Cool.
Safari – older extension, but just tacking parameter to URL so should work.
Playing with functional PHP wondered if array_map was more efficient than a foreach loop.
Trigger value – caused issues when I forgot. Hence mods to extension. Not sure why they are needed.
Format: 0 = human, 1 = computer, 2 = html
Output_dir - make sure it’s writable by web server.
Allows to collapse trace branches
Note info – time, memory, etc.
The same a traces, with different pictures.
Same as traces, but different options for output_name
Note cachegrind format requires special reader.
It must be better than PHPStorm because it has more colors.
All other tools are read / report.
Debug requires coordinated communication.
More complicated.
Request has xdebug parameter
Coordinate over dbgp during execution
Responses sent as needed.
Autostart – always try to run
Remote_connect_back vs remote_host – one or the other, not both.
Connect_back good for shared dev box.
Firewall issue: port 9000 blocked. Remote host = localhost.