Debugging PHP with Xdebug
description
Transcript of Debugging PHP with Xdebug
![Page 1: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/1.jpg)
{
Debugging PHP with Xdebug
Stephanie RussellZachary Klink
![Page 2: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/2.jpg)
Free and open source Swiss army knife for PHP developers.
Developed by Derick Rethans Written in C Initial release date: May 2, 2002 Stable Release: 2.1.2; July 28, 2011
Xdebug
![Page 3: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/3.jpg)
Stack and function traces in error messages
Full param display for user defined functions
Function name, file name and line number Support for member functions
Memory allocation Protection for infinite recursions Profiling information for PHP scripts Code coverage analysis Debugger front-end to interactively
debug
Features
![Page 4: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/4.jpg)
DBG FirePHP Gubed PHP_Debug MacGDBp
Competition
![Page 5: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/5.jpg)
Performance Pause program execution Usable with Eclipse, Netbeans,
Notepad++, Chrome, Firefox, etc.
Why Xdebug?
![Page 6: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/6.jpg)
{Let’s dive a little deeper…
How to Xdebug
![Page 7: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/7.jpg)
php.ini When enabled, xdebug controls program
execution. As a server
GDB and DBGp Remote control for PHP Embedded into editor (no direct dealing
with protocol itself)
How to Xdebug
![Page 8: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/8.jpg)
Modes: Default: req. Makes xdebug always
connect to client when a script is started. Second mode: jit. Only connect to the
client on a breakpoint or error in script. No setting in xdebug.remote_mode =
default
How to Xdebug
![Page 9: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/9.jpg)
Negatives Potential install/configuration nightmare Compatibility issues
Drawbacks
![Page 10: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/10.jpg)
{How it works!
Internals
![Page 11: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/11.jpg)
With remote debugging, embedded Xdebug in PHP acts as a client, and the IDE acts as a server.
Internals – single dev
The IP of the server is 10.0.1.2 with HTTP on port 80 The IDE is on IP 10.0.1.42, so xdebug.remote_host is set to 10.0.1.42 The IDE listens on port 9000, so xdebug.remote_port is set to 9000 The HTTP request is started on the machine running the IDE Xdebug connects to 10.0.1.42:9000 Debugging runs, HTTP Response provided
![Page 12: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/12.jpg)
Setup is only slightly different:
Internals – multiple dev
The IP of the server is 10.0.1.2 with HTTP on port 80 The IDE is on an unknown IP, so xdebug.remote_connect_back is set to 1 The IDE listens on port 9000, so xdebug.remote_port is set to 9000 The HTTP request is made, Xdebug detects the IP address from the HTTP headers Xdebug connects to the detected IP (10.0.1.42) on port 9000 Debugging runs, HTTP Response provided
![Page 13: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/13.jpg)
Internals – Debug session
Tracks debug session through brower: cookies
URL variable XDEBUG_SESSION_START=name appended to URL
Xdebug emits cookie with name “XDEBUG_SESSION” with value “name.”
This expires in an hour. DBGp protocol also passes this value to
the init packet when connecting to debug client
![Page 14: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/14.jpg)
Internals – Debug session
When there is a GET or POST, the cookie is set, xdebug connects to a debug client.
To stop debug session (and destroy the cookie), add URL parameter XDEBUG_SESSION_STOP.
Xdebug not longer tries to connect to debug client.
![Page 15: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/15.jpg)
Internals – Multiple Users
Can specify one IP or multiple users xdebug.remote_host or
If IP not known: xdebug.remote_connect_back
![Page 16: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/16.jpg)
{Be sure to wear your helmet.
Installation
![Page 17: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/17.jpg)
PHP 5 Apache2
First
![Page 18: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/18.jpg)
Apt-get Compatibility with PHP release
Find installed xdebug.so Edit php.ini file to add zend extension. Remote host/port
Known IP (edit 09/22 or for multiple developers)
Port open
Install
![Page 19: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/19.jpg)
Netbeans Tools > Options > PHP Set debug port = remote_port
Integrate with Netbeans
![Page 20: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/20.jpg)
{Valiantly attempting to avoid Murphy’s law
Demo
![Page 21: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/21.jpg)
{Research is key to success
Resources
![Page 22: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/22.jpg)
http://www.firephp.org/HQ/Use.htm http
://sixrevisions.com/web-development/how-to-debug-php-using-firefox-with-firephp/
http://www.php-debugger.com/dbg/ http://gubed.mccabe.nu/ http://coding.smashingmagazine.com/20
09/01/20/50-extremely-useful-php-tools/
http://www.bluestatic.org/software/macgdbp/
Competition Resources
![Page 23: Debugging PHP with Xdebug](https://reader035.fdocuments.in/reader035/viewer/2022062400/56816930550346895de07b9b/html5/thumbnails/23.jpg)
http://xdebug.org/docs/remote http://
ubuntuforums.org/showthread.php?t=525257 http://scottfaisal.com/installing-xdebug-on-ubunt
u-10-04/
http://2bits.com/articles/setting-up-xdebug-dbgp-for-php-on-debian-ubuntu.html
http://netbeans.org/kb/docs/php/configure-php-environment-ubuntu.html
http://wiki.netbeans.org/HowToConfigureXDebug http://
stackoverflow.com/questions/693074/how-to-debug-php-with-netbeans-and-xdebug
http://blogs.oracle.com/netbeansphp/entry/howto_check_xdebug_installationInstallation Resources