Xdebug
About me
- Vo Xuan Tien
- Drupal developer
- GO1
- 2 years experience
Outline
- Installation
- Features
- Demo
Installation
Ubuntu
sudo apt-get install php5-xdebug
CentOS, Fedora, RHEL, etc.
yum install php-pecl-xdebug.x86_64
Mac OSX using Homebrew
brew tap josegonzalez/homebrew-php
brew install php55-xdebug
Windows
Download .dll files
from http://xdebug.org/download.php
Compile from source
wget http://xdebug.org/files/xdebug-2.3.2.tgz
tar -xvf xdebug-2.3.2.tgz
cd xdebug-2.3.2
phpize && ./configure && make
sudo cp modules/xdebug.so /usr/lib/php5/20121212/
Wizard
Paste your phpinfo() here:
http://xdebug.org/wizard.php
Configuration
(localhost)
; /etc/php5/mods-available/xdebug.ini
zend_extension=xdebug.so
[xdebug]
xdebug.remote_host=localhost
xdebug.remote_connect_back=0
xdebug.remote_enable=1
xdebug.remote_autostart = 0
xdebug.default_enable = 1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.idekey=”netbeans-xdebug”
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger = 1
Configuration
(lan)
; /etc/php5/mods-available/xdebug.ini
zend_extension=xdebug.so
[xdebug]
xdebug.remote_host=192.168.1.234
xdebug.remote_connect_back=0
xdebug.remote_enable=1
xdebug.remote_autostart = 0
xdebug.default_enable = 1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.idekey=”netbeans-xdebug”
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger = 1
Configuration
(virtualbox)
; /etc/php5/mods-available/xdebug.ini
zend_extension=xdebug.so
[xdebug]
xdebug.remote_host=192.168.56.1
xdebug.remote_connect_back=0
xdebug.remote_enable=1
xdebug.remote_autostart = 0
xdebug.default_enable = 1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.idekey=”netbeans-xdebug”
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger = 1
Configuration
(unknow ip)
; /etc/php5/mods-available/xdebug.ini
zend_extension=xdebug.so
[xdebug]
; xdebug.remote_host=localhost
xdebug.remote_connect_back=1
xdebug.remote_enable=1
xdebug.remote_autostart = 0
xdebug.default_enable = 1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.idekey=”netbeans-xdebug”
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger = 1
Debug
(bash)
; ~/.bashrc
export XDEBUG_CONFIG="idekey=netbeans-xdebug"
Profiling
(bash)
; ~/.bashrc
export XDEBUG_CONFIG="profiler_enable=1"
; Or
alias phpx='XDEBUG_CONFIG="profiler_enable=1" php'
Configuration
(firewalls)
#!/bin/sh
# Set-up a tunnel
ssh -R 9000:localhost:9000 username@dev.example.com
Configuration
(path mapping)
Features
- Remote debugging
- Code coverage analysis
- Profiling PHP scripts
Remote debugging
- We need a client (PHPStorm, Netbeans)
- Make sure client listen for debug connections.
- We need to start a debug session
- We can start debug session via:
- Command line
- Web browser
- Browser extension for FF, Chrome, Safari, Opera
Code coverage analysis
- Tell you which lines of script (or set of scripts) have been executed during a request
- Tell you how good your unit tests are
Profiling PHP scripts
- Determine bottle neck
- We need a tool to read output
- KCacheGrind
- WinCacheGrind
- Webgrind
Demo
Demo
Demo
Demo
References
Q&A
PHP Meetup xdebug
By Tiến Võ Xuân
PHP Meetup xdebug
- 2,138