SlideShare a Scribd company logo
1 of 87
Download to read offline
D E B U G G I N G P H P W I T H
X D E B U G
M A R K N I E B E R G A L L
https://joind.in/talk/50bee
D E B U G G I N G P H P W I T H
X D E B U G
A B O U T M A R K N I E B E R G A L L
• PHP since 2005
• Masters degree in MIS
• Senior Software Engineer
• Drug screening project
• UPHPU President
• CSSLP, SSCP Certified and SME
• Drones, fishing, skiing, father, husband
A B O U T M A R K N I E B E R G A L L
• Manchester
• Nelson
• Workington
A B O U T M A R K N I E B E R G A L L
A B O U T M A R K N I E B E R G A L L
D E B U G G I N G P H P W I T H X D E B U G
Overview
• What is Xdebug
• Why use Xdebug
• Setting up Xdebug
• Using Xdebug
W H AT I S X D E B U G
W H AT I S X D E B U G
W H AT I S X D E B U G
Xdebug
• Step-into debugger
• Profiler
• DeBugGer Protocol (DBGp) for communication
W H AT I S X D E B U G
Xdebug
• Available since 2002
• Developed initially by Derick Rethans
• PHP extension
• Written in C
• Open source
W H Y U S E X D E B U G
W H Y U S E X D E B U G
Debugging without Xdebug
W H Y U S E X D E B U G
Debugging without Xdebug
• echo $something;
• var_dump($other);
• print_r($data);
• error_log(__FILE__ . ‘ line ‘ . __LINE__);
W H Y U S E X D E B U G
Debugging without Xdebug
1. Add outputs
2. Load page
3. Look for output
4. Change some code
5. Add more outputs
6. Repeat
7. Cleanup outputs without missing any
8. Load page
W H Y U S E X D E B U G
Debugging with Xdebug
W H Y U S E X D E B U G
Debugging with Xdebug
1. Turn on debugging
2. Add breakpoint(s)
3. Load page
4. Step into the code
W H Y U S E X D E B U G
Debugging with Xdebug
• Live values
• Follow actual code path
• Full stacktrace
W H Y U S E X D E B U G
Debugging with Xdebug
• Supported by most IDEs
• Faster development time
• Better understanding of what code is actually doing
• Does not require code changes to interrogate values
S E T T I N G U P X D E B U G
S E T T I N G U P X D E B U G
Fire up you development environment
S E T T I N G U P X D E B U G
Documentation from JetBrain for PhpStorm
https://confluence.jetbrains.com/display/PhpStorm/Zero-
configuration+Web+Application+Debugging+with+Xdebug+and+PhpStorm
1. Install Xdebug
2. Prepare PhpStorm
3. Set a breakpoint in the source code
4. Activate debugger on server
5. Start a debug session in browser
6. Reload the current page
7. Set initial path mappings
S E T T I N G U P X D E B U G
1. Install Xdebug
S E T T I N G U P X D E B U G
1. Install Xdebug
• https://xdebug.org/docs/install
S E T T I N G U P X D E B U G
1. Install Xdebug
• Download (if applicable)
• Install or compile
• Configure PHP
• Restart webserver
S E T T I N G U P X D E B U G
1. Install Xdebug
• git clone https://github.com/xdebug/xdebug.git
• cd xdebug
• ./rebuild.sh
S E T T I N G U P X D E B U G
1. Install Xdebug
• Windows:
- Xdebug website has a wizard, dll downloads
• Mac:
- sudo pecl install xdebug
- brew install php72-xdebug
• Linux:
- wget http://xdebug.org/files/xdebug-2.6.0.tgz
- sudo pecl install xdebug
S E T T I N G U P X D E B U G
1. Install Xdebug
• Windows: download dll
- Xdebug website has a wizard, downloads
- Paste php -i or phpinfo() (ex: C:phpphp -i > C:
phpphpinfo.txt or <?php phpinfo();)
- dll download link provided
- Add a line to your php.ini file
- Restart webserver
S E T T I N G U P X D E B U G
1. Install Xdebug
• apt-get install php-xdebug
• wget http://xdebug.org/files/xdebug-2.6.0.tgz

tar -xzvf xdebug-2.6.0.tgz

cd xdebug-2.6.0

phpize

./configure --enable-xdebug

make

make install
S E T T I N G U P X D E B U G
1. Install Xdebug
• yum install php-devel

yum install php-pear

pecl install xdebug
• dnf install php-devel

dnf install php-pear

pecl install xdebug
S E T T I N G U P X D E B U G
1. Install Xdebug
• Update php.ini by adding lines:



zend_extension = php_xdebug-2.6.0-7.2-vc15-nts-x86_64.dll



[xdebug]

xdebug.remote_enable = 1

xdebug.remote_autostart = 1

xdebug.remote_port = 9000

xdebug.remote_host = localhost

xdebug.idekey = PHPSTORM

S E T T I N G U P X D E B U G
1. Install Xdebug
• Update php.ini by adding lines:



zend_extension = /usr/lib64/php/modules/xdebug.so



[xdebug]

xdebug.remote_enable = 1

xdebug.remote_autostart = 1

xdebug.remote_port = 9000

xdebug.remote_host = localhost

xdebug.idekey = PHPSTORM

S E T T I N G U P X D E B U G
1. Install Xdebug
• Restart webserver
- Windows:

Services

Apache Monitor
- Linux:

sudo apachectl restart

sudo service nginx restart
S E T T I N G U P X D E B U G
1. Install Xdebug
• Verify via phpinfo
- <?php phpinfo();
- php -i | grep xdebug
S E T T I N G U P X D E B U G
1. Install Xdebug
• Verify via phpinfo
S E T T I N G U P X D E B U G
1. Install Xdebug
• Verify via phpinfo
S E T T I N G U P X D E B U G
2. Prepare PhpStorm
S E T T I N G U P X D E B U G
2. Prepare PhpStorm
• Start Listening for PHP Debug Connections
S E T T I N G U P X D E B U G
2. Prepare PhpStorm
S E T T I N G U P X D E B U G
2. Prepare PhpStorm
S E T T I N G U P X D E B U G
2. Prepare PhpStorm
• Setup debug settings
S E T T I N G U P X D E B U G
2. Prepare PhpStorm
• Setup project path mapping
S E T T I N G U P X D E B U G
2. Prepare PhpStorm
S E T T I N G U P X D E B U G
3. Set a breakpoint in the source code
S E T T I N G U P X D E B U G
3. Set a breakpoint in the source code
• Line you know will be hit
• Or break on first line
S E T T I N G U P X D E B U G
4. Activate debugger on server
S E T T I N G U P X D E B U G
4. Activate debugger on server
• Browser plugin, add-on
- The easiest Xdebug (Firefox)
- Xdebug Helper (Chrome)
- Xdebug Toggler (Safari)
- Xdebug launcher (Opera)
S E T T I N G U P X D E B U G
4. Activate debugger on server
S E T T I N G U P X D E B U G
4. Activate debugger on server
S E T T I N G U P X D E B U G
4. Activate debugger on server
• URL
- GET: &XDEBUG_SESSION_START=PHPSTORM
- POST: XDEBUG_SESSION_START=PHPSTORM
• Headers
- Name: Cookie
- Value: XDEBUG_SESSION=PHPSTORM
• Bookmarklet
S E T T I N G U P X D E B U G
4. Activate debugger on server
S E T T I N G U P X D E B U G
4. Activate debugger on server
S E T T I N G U P X D E B U G
4. Activate debugger on server
S E T T I N G U P X D E B U G
4. Activate debugger on server
S E T T I N G U P X D E B U G
4. Activate debugger on server
S E T T I N G U P X D E B U G
4. Activate debugger on server
S E T T I N G U P X D E B U G
4. Activate debugger on server
S E T T I N G U P X D E B U G
5. Start a debug session in browser
S E T T I N G U P X D E B U G
5. Start a debug session in browser
• Click the debug button in toolbar
• Add GET, POST, or COOKIE
S E T T I N G U P X D E B U G
6. Reload the current page
S E T T I N G U P X D E B U G
6. Reload the current page
S E T T I N G U P X D E B U G
7. Set initial path mappings
S E T T I N G U P X D E B U G
7. Set initial path mappings
U S I N G X D E B U G
U S I N G X D E B U G
U S I N G X D E B U G
• Breakpoints
• Stepping through code
• Watches
• Console
U S I N G X D E B U G
U S I N G X D E B U G
Breakpoints
• Pause code execution at specific line
• Allowed multiple breakpoints
• Conditional breakpoints
U S I N G X D E B U G
Breakpoints
• Place strategically
• Not too early
• Not too late
• Not too many
• Remember time limit, increase if needed
• Use conditional breakpoints in loops
U S I N G X D E B U G
Breakpoints
U S I N G X D E B U G
Breakpoints
U S I N G X D E B U G
Stepping through code
U S I N G X D E B U G
Stepping through code
• Resume Program (Play)
• Stop
• View Breakpoints
• Disable All Breakpoints
U S I N G X D E B U G
Stepping through code
• Step Over
• Step Into
• Force Step Into
• Step Out
• Run to Cursor
U S I N G X D E B U G
Stepping through code
• Evaluate Expression
• Show value addresses
• Hide empty superglobal variables (on by default)
• Add method to skip list
U S I N G X D E B U G
Watches
U S I N G X D E B U G
Watches
• Live updates
• Values
• Expressions
U S I N G X D E B U G
Console
U S I N G X D E B U G
Console
• Output from debugging expressions
• Enter expressions to be evaluated
S U M M A RY
S U M M A RY
• More efficient way to debug
• Visibility into code
• Ability to change code on the fly
• Watch values change line by line
• Better understanding of code path
D I S C U S S I O N
• Setup issues
• Remote debugging
• Profiling
• Xdebug vs alternative methods
Q U E S T I O N S ?
https://joind.in/talk/50bee
S O U R C E S
• JetBrains documentation https://confluence.jetbrains.com/display/PhpStorm/Zero-
configuration+Web+Application+Debugging+with+Xdebug+and+PhpStorm
• Xdebug documentation https://xdebug.org/docs/install
• David Stockton, php[architect], January 2015, https://www.phparch.com/wp-
content/uploads/2015/01/levelup-xdebug-phparchitect-jan2015.pdf
• https://sievertschreiber.files.wordpress.com/2010/04/crane-truck-double-fail.jpg

More Related Content

What's hot

Preparing code for Php 7 workshop
Preparing code for Php 7 workshopPreparing code for Php 7 workshop
Preparing code for Php 7 workshopDamien Seguy
 
Puppet Continuous Integration with PE and GitLab
Puppet Continuous Integration with PE and GitLabPuppet Continuous Integration with PE and GitLab
Puppet Continuous Integration with PE and GitLabAlessandro Franceschi
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAndrii Soldatenko
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Wim Godden
 
How to inspect a RUNNING perl process
How to inspect a RUNNING perl processHow to inspect a RUNNING perl process
How to inspect a RUNNING perl processMasaaki HIROSE
 
Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)James Titcumb
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitJames Fuller
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6Wim Godden
 
How to deploy node to production
How to deploy node to productionHow to deploy node to production
How to deploy node to productionSean Hess
 
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5Wim Godden
 
The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5Wim Godden
 
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)Ontico
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2LiviaLiaoFontech
 
Zend Framework 1.8 workshop
Zend Framework 1.8 workshopZend Framework 1.8 workshop
Zend Framework 1.8 workshopNick Belhomme
 

What's hot (20)

Preparing code for Php 7 workshop
Preparing code for Php 7 workshopPreparing code for Php 7 workshop
Preparing code for Php 7 workshop
 
Puppet Continuous Integration with PE and GitLab
Puppet Continuous Integration with PE and GitLabPuppet Continuous Integration with PE and GitLab
Puppet Continuous Integration with PE and GitLab
 
Advanced debugging  techniques in different environments
Advanced debugging  techniques in different environmentsAdvanced debugging  techniques in different environments
Advanced debugging  techniques in different environments
 
Effective Benchmarks
Effective BenchmarksEffective Benchmarks
Effective Benchmarks
 
Nginx pres
Nginx presNginx pres
Nginx pres
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
 
How to inspect a RUNNING perl process
How to inspect a RUNNING perl processHow to inspect a RUNNING perl process
How to inspect a RUNNING perl process
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 
Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)Diving into HHVM Extensions (PHPNW Conference 2015)
Diving into HHVM Extensions (PHPNW Conference 2015)
 
Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
 
Getting Testy With Perl6
Getting Testy With Perl6Getting Testy With Perl6
Getting Testy With Perl6
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6
 
How to deploy node to production
How to deploy node to productionHow to deploy node to production
How to deploy node to production
 
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 
The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5The why and how of moving to php 5.4/5.5
The why and how of moving to php 5.4/5.5
 
Smoking docker
Smoking dockerSmoking docker
Smoking docker
 
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)
HHVM: Efficient and Scalable PHP/Hack Execution / Guilherme Ottoni (Facebook)
 
2021.laravelconf.tw.slides2
2021.laravelconf.tw.slides22021.laravelconf.tw.slides2
2021.laravelconf.tw.slides2
 
Zend Framework 1.8 workshop
Zend Framework 1.8 workshopZend Framework 1.8 workshop
Zend Framework 1.8 workshop
 

Similar to Debug PHP code like a pro with Xdebug

Debugging PHP With Xdebug
Debugging PHP With XdebugDebugging PHP With Xdebug
Debugging PHP With XdebugMark Niebergall
 
Plugin Development @ WordCamp Norway 2014
Plugin Development @ WordCamp Norway 2014Plugin Development @ WordCamp Norway 2014
Plugin Development @ WordCamp Norway 2014Barry Kooij
 
200,000 Lines Later: Our Journey to Manageable Puppet Code
200,000 Lines Later: Our Journey to Manageable Puppet Code200,000 Lines Later: Our Journey to Manageable Puppet Code
200,000 Lines Later: Our Journey to Manageable Puppet CodeDavid Danzilio
 
Testing Your Automation Code (Vagrant Version)
Testing Your Automation Code (Vagrant Version)Testing Your Automation Code (Vagrant Version)
Testing Your Automation Code (Vagrant Version)Mischa Taylor
 
Autotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsAutotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsArtur Babyuk
 
ASP.NET 5 on the Raspberry PI 2
ASP.NET 5 on the Raspberry PI 2ASP.NET 5 on the Raspberry PI 2
ASP.NET 5 on the Raspberry PI 2Jürgen Gutsch
 
We Make Debugging Sucks Less
We Make Debugging Sucks LessWe Make Debugging Sucks Less
We Make Debugging Sucks LessAlon Fliess
 
Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...
Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...
Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...MarcinStachniuk
 
OSDC 2016 - Continous Integration in Data Centers - Further 3 Years later by ...
OSDC 2016 - Continous Integration in Data Centers - Further 3 Years later by ...OSDC 2016 - Continous Integration in Data Centers - Further 3 Years later by ...
OSDC 2016 - Continous Integration in Data Centers - Further 3 Years later by ...NETWAYS
 
Intro to WordPress Plugins
Intro to WordPress PluginsIntro to WordPress Plugins
Intro to WordPress Pluginszamoose
 
Chef - Administration for programmers
Chef - Administration for programmersChef - Administration for programmers
Chef - Administration for programmersmrsabo
 
goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020
goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020
goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020AWSKRUG - AWS한국사용자모임
 
Testing your-automation-code (vagrant version) v0.2
Testing your-automation-code (vagrant version) v0.2Testing your-automation-code (vagrant version) v0.2
Testing your-automation-code (vagrant version) v0.2Sylvain Tissot
 
JupyterHub tutorial at JupyterCon
JupyterHub tutorial at JupyterConJupyterHub tutorial at JupyterCon
JupyterHub tutorial at JupyterConCarol Willing
 
Web a Quebec - JS Debugging
Web a Quebec - JS DebuggingWeb a Quebec - JS Debugging
Web a Quebec - JS DebuggingRami Sayar
 
Docker for Development
Docker for DevelopmentDocker for Development
Docker for Developmentallingeek
 
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...Chef Software, Inc.
 
Introduction to Xdebug
Introduction to XdebugIntroduction to Xdebug
Introduction to XdebugAbid Malik
 

Similar to Debug PHP code like a pro with Xdebug (20)

Debugging PHP With Xdebug
Debugging PHP With XdebugDebugging PHP With Xdebug
Debugging PHP With Xdebug
 
Plugin Development @ WordCamp Norway 2014
Plugin Development @ WordCamp Norway 2014Plugin Development @ WordCamp Norway 2014
Plugin Development @ WordCamp Norway 2014
 
200,000 Lines Later: Our Journey to Manageable Puppet Code
200,000 Lines Later: Our Journey to Manageable Puppet Code200,000 Lines Later: Our Journey to Manageable Puppet Code
200,000 Lines Later: Our Journey to Manageable Puppet Code
 
Testing Your Automation Code (Vagrant Version)
Testing Your Automation Code (Vagrant Version)Testing Your Automation Code (Vagrant Version)
Testing Your Automation Code (Vagrant Version)
 
Autotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsAutotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP Basics
 
ASP.NET 5 on the Raspberry PI 2
ASP.NET 5 on the Raspberry PI 2ASP.NET 5 on the Raspberry PI 2
ASP.NET 5 on the Raspberry PI 2
 
We Make Debugging Sucks Less
We Make Debugging Sucks LessWe Make Debugging Sucks Less
We Make Debugging Sucks Less
 
Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...
Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...
Java Web Start czyli jak żyć z tą dziwną technologią & Continuous Delivery w ...
 
OSDC 2016 - Continous Integration in Data Centers - Further 3 Years later by ...
OSDC 2016 - Continous Integration in Data Centers - Further 3 Years later by ...OSDC 2016 - Continous Integration in Data Centers - Further 3 Years later by ...
OSDC 2016 - Continous Integration in Data Centers - Further 3 Years later by ...
 
Intro to WordPress Plugins
Intro to WordPress PluginsIntro to WordPress Plugins
Intro to WordPress Plugins
 
Chef - Administration for programmers
Chef - Administration for programmersChef - Administration for programmers
Chef - Administration for programmers
 
goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020
goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020
goployer, 코드 기반의 배포 도구 - 송주영 (beNX) :: AWS Community Day 2020
 
Testing your-automation-code (vagrant version) v0.2
Testing your-automation-code (vagrant version) v0.2Testing your-automation-code (vagrant version) v0.2
Testing your-automation-code (vagrant version) v0.2
 
JupyterHub tutorial at JupyterCon
JupyterHub tutorial at JupyterConJupyterHub tutorial at JupyterCon
JupyterHub tutorial at JupyterCon
 
Web a Quebec - JS Debugging
Web a Quebec - JS DebuggingWeb a Quebec - JS Debugging
Web a Quebec - JS Debugging
 
Docker for Development
Docker for DevelopmentDocker for Development
Docker for Development
 
Don't Mind the Gap by Galen Emery
Don't Mind the Gap by Galen EmeryDon't Mind the Gap by Galen Emery
Don't Mind the Gap by Galen Emery
 
Don't Mind the Gap by Galen Emery
Don't Mind the Gap by Galen EmeryDon't Mind the Gap by Galen Emery
Don't Mind the Gap by Galen Emery
 
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
Chef Fundamentals Training Series Module 3: Setting up Nodes and Cookbook Aut...
 
Introduction to Xdebug
Introduction to XdebugIntroduction to Xdebug
Introduction to Xdebug
 

More from Mark Niebergall

Filesystem Management with Flysystem - php[tek] 2023
Filesystem Management with Flysystem - php[tek] 2023Filesystem Management with Flysystem - php[tek] 2023
Filesystem Management with Flysystem - php[tek] 2023Mark Niebergall
 
Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023Mark Niebergall
 
Filesystem Management with Flysystem at PHP UK 2023
Filesystem Management with Flysystem at PHP UK 2023Filesystem Management with Flysystem at PHP UK 2023
Filesystem Management with Flysystem at PHP UK 2023Mark Niebergall
 
Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Mark Niebergall
 
Unit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentUnit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentMark Niebergall
 
BDD API Tests with Gherkin and Behat
BDD API Tests with Gherkin and BehatBDD API Tests with Gherkin and Behat
BDD API Tests with Gherkin and BehatMark Niebergall
 
BDD API Tests with Gherkin and Behat
BDD API Tests with Gherkin and BehatBDD API Tests with Gherkin and Behat
BDD API Tests with Gherkin and BehatMark Niebergall
 
Relational Database Design Bootcamp
Relational Database Design BootcampRelational Database Design Bootcamp
Relational Database Design BootcampMark Niebergall
 
Advanced PHP Simplified - Sunshine PHP 2018
Advanced PHP Simplified - Sunshine PHP 2018Advanced PHP Simplified - Sunshine PHP 2018
Advanced PHP Simplified - Sunshine PHP 2018Mark Niebergall
 
Defensive Coding Crash Course Tutorial
Defensive Coding Crash Course TutorialDefensive Coding Crash Course Tutorial
Defensive Coding Crash Course TutorialMark Niebergall
 
Inheritance: Vertical or Horizontal
Inheritance: Vertical or HorizontalInheritance: Vertical or Horizontal
Inheritance: Vertical or HorizontalMark Niebergall
 
Cybersecurity State of the Union
Cybersecurity State of the UnionCybersecurity State of the Union
Cybersecurity State of the UnionMark Niebergall
 
Cryptography With PHP - ZendCon 2017 Workshop
Cryptography With PHP - ZendCon 2017 WorkshopCryptography With PHP - ZendCon 2017 Workshop
Cryptography With PHP - ZendCon 2017 WorkshopMark Niebergall
 
Defensive Coding Crash Course - ZendCon 2017
Defensive Coding Crash Course - ZendCon 2017Defensive Coding Crash Course - ZendCon 2017
Defensive Coding Crash Course - ZendCon 2017Mark Niebergall
 
Leveraging Composer in Existing Projects
Leveraging Composer in Existing ProjectsLeveraging Composer in Existing Projects
Leveraging Composer in Existing ProjectsMark Niebergall
 
Defensive Coding Crash Course
Defensive Coding Crash CourseDefensive Coding Crash Course
Defensive Coding Crash CourseMark Niebergall
 
Impostor Syndrome: Be Proud of Your Achievements!
Impostor Syndrome: Be Proud of Your Achievements!Impostor Syndrome: Be Proud of Your Achievements!
Impostor Syndrome: Be Proud of Your Achievements!Mark Niebergall
 

More from Mark Niebergall (20)

Filesystem Management with Flysystem - php[tek] 2023
Filesystem Management with Flysystem - php[tek] 2023Filesystem Management with Flysystem - php[tek] 2023
Filesystem Management with Flysystem - php[tek] 2023
 
Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023Leveling Up With Unit Testing - php[tek] 2023
Leveling Up With Unit Testing - php[tek] 2023
 
Filesystem Management with Flysystem at PHP UK 2023
Filesystem Management with Flysystem at PHP UK 2023Filesystem Management with Flysystem at PHP UK 2023
Filesystem Management with Flysystem at PHP UK 2023
 
Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022
 
Developing SOLID Code
Developing SOLID CodeDeveloping SOLID Code
Developing SOLID Code
 
Unit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentUnit Testing from Setup to Deployment
Unit Testing from Setup to Deployment
 
BDD API Tests with Gherkin and Behat
BDD API Tests with Gherkin and BehatBDD API Tests with Gherkin and Behat
BDD API Tests with Gherkin and Behat
 
BDD API Tests with Gherkin and Behat
BDD API Tests with Gherkin and BehatBDD API Tests with Gherkin and Behat
BDD API Tests with Gherkin and Behat
 
Hacking with PHP
Hacking with PHPHacking with PHP
Hacking with PHP
 
Relational Database Design Bootcamp
Relational Database Design BootcampRelational Database Design Bootcamp
Relational Database Design Bootcamp
 
Starting Out With PHP
Starting Out With PHPStarting Out With PHP
Starting Out With PHP
 
Advanced PHP Simplified - Sunshine PHP 2018
Advanced PHP Simplified - Sunshine PHP 2018Advanced PHP Simplified - Sunshine PHP 2018
Advanced PHP Simplified - Sunshine PHP 2018
 
Defensive Coding Crash Course Tutorial
Defensive Coding Crash Course TutorialDefensive Coding Crash Course Tutorial
Defensive Coding Crash Course Tutorial
 
Inheritance: Vertical or Horizontal
Inheritance: Vertical or HorizontalInheritance: Vertical or Horizontal
Inheritance: Vertical or Horizontal
 
Cybersecurity State of the Union
Cybersecurity State of the UnionCybersecurity State of the Union
Cybersecurity State of the Union
 
Cryptography With PHP - ZendCon 2017 Workshop
Cryptography With PHP - ZendCon 2017 WorkshopCryptography With PHP - ZendCon 2017 Workshop
Cryptography With PHP - ZendCon 2017 Workshop
 
Defensive Coding Crash Course - ZendCon 2017
Defensive Coding Crash Course - ZendCon 2017Defensive Coding Crash Course - ZendCon 2017
Defensive Coding Crash Course - ZendCon 2017
 
Leveraging Composer in Existing Projects
Leveraging Composer in Existing ProjectsLeveraging Composer in Existing Projects
Leveraging Composer in Existing Projects
 
Defensive Coding Crash Course
Defensive Coding Crash CourseDefensive Coding Crash Course
Defensive Coding Crash Course
 
Impostor Syndrome: Be Proud of Your Achievements!
Impostor Syndrome: Be Proud of Your Achievements!Impostor Syndrome: Be Proud of Your Achievements!
Impostor Syndrome: Be Proud of Your Achievements!
 

Recently uploaded

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 

Recently uploaded (20)

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 

Debug PHP code like a pro with Xdebug

  • 1. D E B U G G I N G P H P W I T H X D E B U G M A R K N I E B E R G A L L https://joind.in/talk/50bee
  • 2.
  • 3. D E B U G G I N G P H P W I T H X D E B U G
  • 4. A B O U T M A R K N I E B E R G A L L • PHP since 2005 • Masters degree in MIS • Senior Software Engineer • Drug screening project • UPHPU President • CSSLP, SSCP Certified and SME • Drones, fishing, skiing, father, husband
  • 5. A B O U T M A R K N I E B E R G A L L • Manchester • Nelson • Workington
  • 6. A B O U T M A R K N I E B E R G A L L
  • 7. A B O U T M A R K N I E B E R G A L L
  • 8. D E B U G G I N G P H P W I T H X D E B U G Overview • What is Xdebug • Why use Xdebug • Setting up Xdebug • Using Xdebug
  • 9. W H AT I S X D E B U G
  • 10. W H AT I S X D E B U G
  • 11. W H AT I S X D E B U G Xdebug • Step-into debugger • Profiler • DeBugGer Protocol (DBGp) for communication
  • 12. W H AT I S X D E B U G Xdebug • Available since 2002 • Developed initially by Derick Rethans • PHP extension • Written in C • Open source
  • 13. W H Y U S E X D E B U G
  • 14. W H Y U S E X D E B U G Debugging without Xdebug
  • 15. W H Y U S E X D E B U G Debugging without Xdebug • echo $something; • var_dump($other); • print_r($data); • error_log(__FILE__ . ‘ line ‘ . __LINE__);
  • 16. W H Y U S E X D E B U G Debugging without Xdebug 1. Add outputs 2. Load page 3. Look for output 4. Change some code 5. Add more outputs 6. Repeat 7. Cleanup outputs without missing any 8. Load page
  • 17. W H Y U S E X D E B U G Debugging with Xdebug
  • 18. W H Y U S E X D E B U G Debugging with Xdebug 1. Turn on debugging 2. Add breakpoint(s) 3. Load page 4. Step into the code
  • 19. W H Y U S E X D E B U G Debugging with Xdebug • Live values • Follow actual code path • Full stacktrace
  • 20. W H Y U S E X D E B U G Debugging with Xdebug • Supported by most IDEs • Faster development time • Better understanding of what code is actually doing • Does not require code changes to interrogate values
  • 21. S E T T I N G U P X D E B U G
  • 22. S E T T I N G U P X D E B U G Fire up you development environment
  • 23. S E T T I N G U P X D E B U G Documentation from JetBrain for PhpStorm https://confluence.jetbrains.com/display/PhpStorm/Zero- configuration+Web+Application+Debugging+with+Xdebug+and+PhpStorm 1. Install Xdebug 2. Prepare PhpStorm 3. Set a breakpoint in the source code 4. Activate debugger on server 5. Start a debug session in browser 6. Reload the current page 7. Set initial path mappings
  • 24. S E T T I N G U P X D E B U G 1. Install Xdebug
  • 25. S E T T I N G U P X D E B U G 1. Install Xdebug • https://xdebug.org/docs/install
  • 26. S E T T I N G U P X D E B U G 1. Install Xdebug • Download (if applicable) • Install or compile • Configure PHP • Restart webserver
  • 27. S E T T I N G U P X D E B U G 1. Install Xdebug • git clone https://github.com/xdebug/xdebug.git • cd xdebug • ./rebuild.sh
  • 28. S E T T I N G U P X D E B U G 1. Install Xdebug • Windows: - Xdebug website has a wizard, dll downloads • Mac: - sudo pecl install xdebug - brew install php72-xdebug • Linux: - wget http://xdebug.org/files/xdebug-2.6.0.tgz - sudo pecl install xdebug
  • 29. S E T T I N G U P X D E B U G 1. Install Xdebug • Windows: download dll - Xdebug website has a wizard, downloads - Paste php -i or phpinfo() (ex: C:phpphp -i > C: phpphpinfo.txt or <?php phpinfo();) - dll download link provided - Add a line to your php.ini file - Restart webserver
  • 30. S E T T I N G U P X D E B U G 1. Install Xdebug • apt-get install php-xdebug • wget http://xdebug.org/files/xdebug-2.6.0.tgz
 tar -xzvf xdebug-2.6.0.tgz
 cd xdebug-2.6.0
 phpize
 ./configure --enable-xdebug
 make
 make install
  • 31. S E T T I N G U P X D E B U G 1. Install Xdebug • yum install php-devel
 yum install php-pear
 pecl install xdebug • dnf install php-devel
 dnf install php-pear
 pecl install xdebug
  • 32. S E T T I N G U P X D E B U G 1. Install Xdebug • Update php.ini by adding lines:
 
 zend_extension = php_xdebug-2.6.0-7.2-vc15-nts-x86_64.dll
 
 [xdebug]
 xdebug.remote_enable = 1
 xdebug.remote_autostart = 1
 xdebug.remote_port = 9000
 xdebug.remote_host = localhost
 xdebug.idekey = PHPSTORM

  • 33. S E T T I N G U P X D E B U G 1. Install Xdebug • Update php.ini by adding lines:
 
 zend_extension = /usr/lib64/php/modules/xdebug.so
 
 [xdebug]
 xdebug.remote_enable = 1
 xdebug.remote_autostart = 1
 xdebug.remote_port = 9000
 xdebug.remote_host = localhost
 xdebug.idekey = PHPSTORM

  • 34. S E T T I N G U P X D E B U G 1. Install Xdebug • Restart webserver - Windows:
 Services
 Apache Monitor - Linux:
 sudo apachectl restart
 sudo service nginx restart
  • 35. S E T T I N G U P X D E B U G 1. Install Xdebug • Verify via phpinfo - <?php phpinfo(); - php -i | grep xdebug
  • 36. S E T T I N G U P X D E B U G 1. Install Xdebug • Verify via phpinfo
  • 37. S E T T I N G U P X D E B U G 1. Install Xdebug • Verify via phpinfo
  • 38. S E T T I N G U P X D E B U G 2. Prepare PhpStorm
  • 39. S E T T I N G U P X D E B U G 2. Prepare PhpStorm • Start Listening for PHP Debug Connections
  • 40. S E T T I N G U P X D E B U G 2. Prepare PhpStorm
  • 41. S E T T I N G U P X D E B U G 2. Prepare PhpStorm
  • 42. S E T T I N G U P X D E B U G 2. Prepare PhpStorm • Setup debug settings
  • 43.
  • 44. S E T T I N G U P X D E B U G 2. Prepare PhpStorm • Setup project path mapping
  • 45. S E T T I N G U P X D E B U G 2. Prepare PhpStorm
  • 46. S E T T I N G U P X D E B U G 3. Set a breakpoint in the source code
  • 47. S E T T I N G U P X D E B U G 3. Set a breakpoint in the source code • Line you know will be hit • Or break on first line
  • 48.
  • 49. S E T T I N G U P X D E B U G 4. Activate debugger on server
  • 50. S E T T I N G U P X D E B U G 4. Activate debugger on server • Browser plugin, add-on - The easiest Xdebug (Firefox) - Xdebug Helper (Chrome) - Xdebug Toggler (Safari) - Xdebug launcher (Opera)
  • 51. S E T T I N G U P X D E B U G 4. Activate debugger on server
  • 52. S E T T I N G U P X D E B U G 4. Activate debugger on server
  • 53. S E T T I N G U P X D E B U G 4. Activate debugger on server • URL - GET: &XDEBUG_SESSION_START=PHPSTORM - POST: XDEBUG_SESSION_START=PHPSTORM • Headers - Name: Cookie - Value: XDEBUG_SESSION=PHPSTORM • Bookmarklet
  • 54. S E T T I N G U P X D E B U G 4. Activate debugger on server
  • 55. S E T T I N G U P X D E B U G 4. Activate debugger on server
  • 56. S E T T I N G U P X D E B U G 4. Activate debugger on server
  • 57. S E T T I N G U P X D E B U G 4. Activate debugger on server
  • 58. S E T T I N G U P X D E B U G 4. Activate debugger on server
  • 59. S E T T I N G U P X D E B U G 4. Activate debugger on server
  • 60. S E T T I N G U P X D E B U G 4. Activate debugger on server
  • 61. S E T T I N G U P X D E B U G 5. Start a debug session in browser
  • 62. S E T T I N G U P X D E B U G 5. Start a debug session in browser • Click the debug button in toolbar • Add GET, POST, or COOKIE
  • 63. S E T T I N G U P X D E B U G 6. Reload the current page
  • 64. S E T T I N G U P X D E B U G 6. Reload the current page
  • 65. S E T T I N G U P X D E B U G 7. Set initial path mappings
  • 66. S E T T I N G U P X D E B U G 7. Set initial path mappings
  • 67. U S I N G X D E B U G
  • 68. U S I N G X D E B U G
  • 69. U S I N G X D E B U G • Breakpoints • Stepping through code • Watches • Console
  • 70. U S I N G X D E B U G
  • 71. U S I N G X D E B U G Breakpoints • Pause code execution at specific line • Allowed multiple breakpoints • Conditional breakpoints
  • 72. U S I N G X D E B U G Breakpoints • Place strategically • Not too early • Not too late • Not too many • Remember time limit, increase if needed • Use conditional breakpoints in loops
  • 73. U S I N G X D E B U G Breakpoints
  • 74. U S I N G X D E B U G Breakpoints
  • 75. U S I N G X D E B U G Stepping through code
  • 76. U S I N G X D E B U G Stepping through code • Resume Program (Play) • Stop • View Breakpoints • Disable All Breakpoints
  • 77. U S I N G X D E B U G Stepping through code • Step Over • Step Into • Force Step Into • Step Out • Run to Cursor
  • 78. U S I N G X D E B U G Stepping through code • Evaluate Expression • Show value addresses • Hide empty superglobal variables (on by default) • Add method to skip list
  • 79. U S I N G X D E B U G Watches
  • 80. U S I N G X D E B U G Watches • Live updates • Values • Expressions
  • 81. U S I N G X D E B U G Console
  • 82. U S I N G X D E B U G Console • Output from debugging expressions • Enter expressions to be evaluated
  • 83. S U M M A RY
  • 84. S U M M A RY • More efficient way to debug • Visibility into code • Ability to change code on the fly • Watch values change line by line • Better understanding of code path
  • 85. D I S C U S S I O N • Setup issues • Remote debugging • Profiling • Xdebug vs alternative methods
  • 86. Q U E S T I O N S ? https://joind.in/talk/50bee
  • 87. S O U R C E S • JetBrains documentation https://confluence.jetbrains.com/display/PhpStorm/Zero- configuration+Web+Application+Debugging+with+Xdebug+and+PhpStorm • Xdebug documentation https://xdebug.org/docs/install • David Stockton, php[architect], January 2015, https://www.phparch.com/wp- content/uploads/2015/01/levelup-xdebug-phparchitect-jan2015.pdf • https://sievertschreiber.files.wordpress.com/2010/04/crane-truck-double-fail.jpg