SlideShare a Scribd company logo
1 of 28
Build better code
Who Am I?
• Selling Source Direct Lead
Developer
• Coupla CTO
• Founder/Organizer of Las
Vegas PHP Users Group
• Co-Organizer of Las Vegas
Developers Users Group
• PHP Machinist Maintainer
• #VegasTech Enthusiast

Adam Englander
adamenglander@yahoo.com
@adam_englander
http://adamknowsstuff.com
https://github.com/derptest
What is Xdebug?
Xdebug is a PHP extension providing:
 Enhanced variable display
 Enhanced stack traces
 Function traces
 Code coverage analysis
 Code profiling
 Remote debugging
Who made Xdebug
Xdebug is written by
Derick Rethans.
Derick is also the author
of the PHP MongoDB
extension. If you’d like
to thank Derick, and you
probably should, you
can use his wish list.
What we’re not talking about
Enhanced variable display
 Enhanced stack traces
 Function traces
 Code coverage analysis


All of these are nice and all but they aren’t
what were talking about.
What we are talking about
Remote debugging:
Step through debugging with a remote
client via the DBGP protocol

Code profiling:
Finding bottlenecks in your code and
visualize those with an external tool such
as KCacheGrind or WinCacheGrind.
Xdebug Remote Debugging
Line by line stepping through code.
 Break points to stop at particular areas of
code.
 Variable inspection to be able to see
variable values at a line of code. Death to
var_dump.
 Variable setting to allow replacement of
variable values at runtime.
 The single best way to troubleshoot bugs.

Xdebug Profiling
Find bottlenecks
 Timings for optimization
 Similar to Cachegrind but no memory
data
 Output format is standard so it can be
read by standard Cachegrind tools:
Kcachegrind, QCacheGrind,
WinCacheGrind, IDE plugins, etc.

Xdebug Requirements


Installing the Xdebug extension
 PEAR/PECL install available
 Available via most Linux package managers

DBGP client for remote debugging –
Debugclient comes with Xdebug source and
a slew of IDEs have built in support.
 Cachegrind analyzer for profiling –
KCachegrind, QCachegrind,
WinCacheGrind, or IDE support.

Remote Debug Configuration
extended_info – Enabled by default.
Allows breakpoints.
 idekey – Identifier for the debug session.
Most clients will restrict to requests from
a single idekey value.
 remote_autostart – Disabled by default.
Will start remote debugging with every
request.

Remote Debug Configuration
remote_connect_back – Disabled by
default. Helpful for debugging on
shared hosts and virtual machines.
Xdebug session will connect to host
making the request.
 remote_cookie_expire_time – Defaults
to 3600 seconds (60 minutes). The time
the debug session cookie will live.

Remote Debug Configuration
remote_enable – Defaults to 0 (off).
Enable remote debugging
 remote_handler – Defaults to DBGP.
You should never have to use anything
else so just leave it.
 remote_host – Remote host with which
Xdebug will connect at the start of an
Xdebug session.

Remote Debug Configuration
remote_log – Default value “”. Log all
remote debugger communication. You
will probably never need this unless you
are writing a client or have connectivity
issues.
 remote_mode – Default value is “req”.
Determines how the session is initiated.
“req” will start the session with every
request. “jit” will start the session when
an error condition occurs.

Remote Debug Configuration


remote_port – Defaults to 9000. TCP/IP
port of the remote client which which
Xdebug will connect. Most clients
default to 9000 so unless you are forced
to debug multiple remote machines, just
leave it.
Profiling Configuration
profiler_append – Default value 0 (off).
Append the profiler output to the same file if
the profile_output_name will allow.
 profiler_enable – Default value 0 (off).
Enable profiling for all requests and script
executions. If you are doing web request
profiling, use profiler_enable_trigger
instead. This should normally be used only
for CLI profiling and configuring via
environment variable.

Profiling Configuration
profiler_enable_trigger – Default value 0
(off). Allow triggering of profiling via
request query parameter or cookie with
the name XDEBUG_PROFILE. The
value is optional and ignored.
 profiler_output_dir – Defaults to “/tmp”.
The directory in which the profiler output
file will be written.

Profiling Configuration


profiler_output_name – Default value is
“cachegrind.out.%p” where %p is the
process ID of the process running the
profile. There are many variable options
like %s for the file name. See the
Xdebug documentation for details:
http://xdebug.org/docs/all_settings#trace
_output_name
Configuring via php.ini
Always prepend option with “xdebug.”
Example:
zend_extension=/usr/local/php/modules/xd
ebug.so
xdebug.remote_enable=1
xdebug.remote_connect_back=1
xdebug.profiler_enable_trigger=1
Configuring via .htaccess
If you have no other options, you can use a
.htaccess file if allowed.
Example:
php_flag xdebug.remote_enable true
php_value xdebug.remote_host “10.0.0.2”
php_flag xdebug.profiler_enable_trigger true
Configuring via environment


When running CLI scripts, you can configure
Xdebug via the XDEBUG_CONFIG variable

Profiling Example:
export XDEBUG_CONFIG=“profiler_enable=1”
Remote Debugging Example:
export XDEBUG_CONFIG=“idekey=key”
Start/Stop Xdebug Sessions
You can start and stop Xdebug remote
debugging and profiling sessions in many
ways:
 IDE integration
 Browser Plugin (Chrome/Firefox/Safari)
 URL parameter
 Cookie
 CLI environment variable
 Xdebug config
Start/Stop via IDE
Most IDEs will have a way to start a
remote debug or profiling session from
the command line or web page.
 See the documentation for your IDE to
learn how to use that.

Start/Stop via Browser Plugin
Browser plugins are a nice simple way
to start and stop an Xebug session
 Available for most browsers.
 Will automatically (un)set the
XDEBUG_SESSION or
XDEBUG_PROFILE cookie.

Start/Stop via URL Parameter
XDEBUG_SESSION_START=idekey
 XDEBUG_SESSION_STOP
 XDEBUG_PROFILE


Example:
http://site.com?XDEBUG_SESSION_START=go
http://site.com?XDEBUG_SESSION_STOP
http://site.com?XDEBUG_PROFILE
Start/Stop via Cookie
Use a cookie named XDEBUG_SESSION with
the value being the idekey value.
Remote Debug Example:
curl --cookie=“XDEBUG_SESSION=eclipse” http://host.com

Profiling Example:
curl --cookie=“XDEBUG_PROFILE=1” http://host.com
Start/Stop via CLI Environment



XDEBUG_CONFIG environment variable will start
stop CLI Xdebug for profiling and debugging
Can be executed for a single script or multiple scripts

Multi-Command Example:
export XDEBUG_CONFIG=“remote_host=localhost”
php script.php
export XDEBUG_CONFIG=
Single Command Example:
XDEBUG_CONFIG=“profiler_enable=1” php script.php
Start/Stop via Xdebug Config
Setting xebug.remote_autostart will start
remote debugging with every execution.
 Setting xdebug.profiler_enable will start
profiling with every execution.
 Requires config change to turn off.
 Try and avoid this. There are so many
better ways.

Demo
Here we go with some code and
examples.

More Related Content

What's hot

Артем Маркушев - JavaScript
Артем Маркушев - JavaScriptАртем Маркушев - JavaScript
Артем Маркушев - JavaScript
DataArt
 
How to deploy node to production
How to deploy node to productionHow to deploy node to production
How to deploy node to production
Sean Hess
 
Design patterns as power of programing
Design patterns as power of programingDesign patterns as power of programing
Design patterns as power of programing
Lukas Lesniewski
 
Speed up your development environment PHP + Nginx + Fedora + PG
Speed up your development environment PHP + Nginx + Fedora + PGSpeed up your development environment PHP + Nginx + Fedora + PG
Speed up your development environment PHP + Nginx + Fedora + PG
Marcus Sá
 

What's hot (20)

Apache Dispatch
Apache DispatchApache Dispatch
Apache Dispatch
 
LSA2 - 03 Http apache nginx
LSA2 - 03 Http apache nginxLSA2 - 03 Http apache nginx
LSA2 - 03 Http apache nginx
 
Server side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPServer side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHP
 
PHP 5.6 New and Deprecated Features
PHP 5.6  New and Deprecated FeaturesPHP 5.6  New and Deprecated Features
PHP 5.6 New and Deprecated Features
 
Xdebug, KCacheGrind and Webgrind with WampServer
Xdebug, KCacheGrind and Webgrind with WampServer  Xdebug, KCacheGrind and Webgrind with WampServer
Xdebug, KCacheGrind and Webgrind with WampServer
 
Артем Маркушев - JavaScript
Артем Маркушев - JavaScriptАртем Маркушев - JavaScript
Артем Маркушев - JavaScript
 
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and VarnishMagento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
Magento 2 Seminar - Miguel Balparda - M2 with PHP 7 and Varnish
 
How to deploy node to production
How to deploy node to productionHow to deploy node to production
How to deploy node to production
 
Design patterns as power of programing
Design patterns as power of programingDesign patterns as power of programing
Design patterns as power of programing
 
Presentation of JSConf.eu
Presentation of JSConf.euPresentation of JSConf.eu
Presentation of JSConf.eu
 
Drizzle plugins
Drizzle pluginsDrizzle plugins
Drizzle plugins
 
Speed up your development environment PHP + Nginx + Fedora + PG
Speed up your development environment PHP + Nginx + Fedora + PGSpeed up your development environment PHP + Nginx + Fedora + PG
Speed up your development environment PHP + Nginx + Fedora + PG
 
Autotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsAutotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP Basics
 
Debugging PHP with Xdebug - PHPUK 2018
Debugging PHP with Xdebug - PHPUK 2018Debugging PHP with Xdebug - PHPUK 2018
Debugging PHP with Xdebug - PHPUK 2018
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4
 
Npm: beyond 'npm i'
Npm: beyond 'npm i'Npm: beyond 'npm i'
Npm: beyond 'npm i'
 
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
 
Automatic PHP 7 Compatibility Checking Using php7cc (and PHPCompatibility)
Automatic PHP 7 Compatibility Checking Using php7cc (and PHPCompatibility)Automatic PHP 7 Compatibility Checking Using php7cc (and PHPCompatibility)
Automatic PHP 7 Compatibility Checking Using php7cc (and PHPCompatibility)
 
Nginx pres
Nginx presNginx pres
Nginx pres
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
 

Similar to Xdebug - Your first, last, and best option for troubleshooting PHP code

Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
phpbarcelona
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability Systems
Marcelo Pinheiro
 

Similar to Xdebug - Your first, last, and best option for troubleshooting PHP code (20)

Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008Xdebug - Derick Rethans - Barcelona PHP Conference 2008
Xdebug - Derick Rethans - Barcelona PHP Conference 2008
 
Debugging PHP with xDebug inside of Eclipse PDT 2.1
Debugging PHP with xDebug inside of Eclipse PDT 2.1Debugging PHP with xDebug inside of Eclipse PDT 2.1
Debugging PHP with xDebug inside of Eclipse PDT 2.1
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
 
Getting Started With Xdebug
Getting Started With XdebugGetting Started With Xdebug
Getting Started With Xdebug
 
PHP Development Tools
PHP  Development ToolsPHP  Development Tools
PHP Development Tools
 
Diagnosing WordPress: What to do when things go wrong
Diagnosing WordPress: What to do when things go wrongDiagnosing WordPress: What to do when things go wrong
Diagnosing WordPress: What to do when things go wrong
 
ApacheConNA 2015: What's new in Apache httpd 2.4
ApacheConNA 2015: What's new in Apache httpd 2.4ApacheConNA 2015: What's new in Apache httpd 2.4
ApacheConNA 2015: What's new in Apache httpd 2.4
 
Improving qa on php projects
Improving qa on php projectsImproving qa on php projects
Improving qa on php projects
 
Magento 2 Development
Magento 2 DevelopmentMagento 2 Development
Magento 2 Development
 
Php Debugger
Php DebuggerPhp Debugger
Php Debugger
 
Porting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability Systems
 
Improving QA on PHP projects - confoo 2011
Improving QA on PHP projects - confoo 2011Improving QA on PHP projects - confoo 2011
Improving QA on PHP projects - confoo 2011
 
Django Deployment-in-AWS
Django Deployment-in-AWSDjango Deployment-in-AWS
Django Deployment-in-AWS
 
ZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small TeamsZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small Teams
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
How to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita GalkinHow to make a high-quality Node.js app, Nikita Galkin
How to make a high-quality Node.js app, Nikita Galkin
 
Madison PHP 2015 - DevOps For Small Teams
Madison PHP 2015 - DevOps For Small TeamsMadison PHP 2015 - DevOps For Small Teams
Madison PHP 2015 - DevOps For Small Teams
 
Cachegrind
CachegrindCachegrind
Cachegrind
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
 
PHP Aberdeen Quick optimisation of PHP with Webgrind
PHP Aberdeen Quick optimisation of PHP with WebgrindPHP Aberdeen Quick optimisation of PHP with Webgrind
PHP Aberdeen Quick optimisation of PHP with Webgrind
 

More from Adam Englander

More from Adam Englander (20)

Making PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptxMaking PHP Smarter - Dutch PHP 2023.pptx
Making PHP Smarter - Dutch PHP 2023.pptx
 
Practical API Security - PyCon 2019
Practical API Security - PyCon 2019Practical API Security - PyCon 2019
Practical API Security - PyCon 2019
 
Threat Modeling for Dummies
Threat Modeling for DummiesThreat Modeling for Dummies
Threat Modeling for Dummies
 
ZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API SecurityZendCon 2018 - Practical API Security
ZendCon 2018 - Practical API Security
 
ZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in DepthZendCon 2018 - Cryptography in Depth
ZendCon 2018 - Cryptography in Depth
 
Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018Threat Modeling for Dummies - Cascadia PHP 2018
Threat Modeling for Dummies - Cascadia PHP 2018
 
Dutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for BeginnersDutch PHP 2018 - Cryptography for Beginners
Dutch PHP 2018 - Cryptography for Beginners
 
php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2108 - Cryptography Advances in PHP 7.2
 
php[tek] 2018 - Biometrics, fantastic failure point of the future
php[tek] 2018 - Biometrics, fantastic failure point of the futurephp[tek] 2018 - Biometrics, fantastic failure point of the future
php[tek] 2018 - Biometrics, fantastic failure point of the future
 
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Biometrics: Sexy, Secure and... Stupid - RSAC 2018Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
 
Practical API Security - PyCon 2018
Practical API Security - PyCon 2018Practical API Security - PyCon 2018
Practical API Security - PyCon 2018
 
Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018Practical API Security - Midwest PHP 2018
Practical API Security - Midwest PHP 2018
 
Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018
 
Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018Cryptography for Beginners - Sunshine PHP 2018
Cryptography for Beginners - Sunshine PHP 2018
 
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the FutureConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
 
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
Con Foo 2017 - Don't Loose Sleep - Secure Your RESTCon Foo 2017 - Don't Loose Sleep - Secure Your REST
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
 
ZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for BeginnersZendCon 2017 - Cryptography for Beginners
ZendCon 2017 - Cryptography for Beginners
 
ZendCon 2017: The Red Team is Coming
ZendCon 2017: The Red Team is ComingZendCon 2017: The Red Team is Coming
ZendCon 2017: The Red Team is Coming
 
ZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async PrimerZendCon 2017 - Build a Bot Workshop - Async Primer
ZendCon 2017 - Build a Bot Workshop - Async Primer
 
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Symfony Live San Franciso 2017 - BDD API Development with Symfony and BehatSymfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Xdebug - Your first, last, and best option for troubleshooting PHP code

  • 2. Who Am I? • Selling Source Direct Lead Developer • Coupla CTO • Founder/Organizer of Las Vegas PHP Users Group • Co-Organizer of Las Vegas Developers Users Group • PHP Machinist Maintainer • #VegasTech Enthusiast Adam Englander adamenglander@yahoo.com @adam_englander http://adamknowsstuff.com https://github.com/derptest
  • 3. What is Xdebug? Xdebug is a PHP extension providing:  Enhanced variable display  Enhanced stack traces  Function traces  Code coverage analysis  Code profiling  Remote debugging
  • 4. Who made Xdebug Xdebug is written by Derick Rethans. Derick is also the author of the PHP MongoDB extension. If you’d like to thank Derick, and you probably should, you can use his wish list.
  • 5. What we’re not talking about Enhanced variable display  Enhanced stack traces  Function traces  Code coverage analysis  All of these are nice and all but they aren’t what were talking about.
  • 6. What we are talking about Remote debugging: Step through debugging with a remote client via the DBGP protocol Code profiling: Finding bottlenecks in your code and visualize those with an external tool such as KCacheGrind or WinCacheGrind.
  • 7. Xdebug Remote Debugging Line by line stepping through code.  Break points to stop at particular areas of code.  Variable inspection to be able to see variable values at a line of code. Death to var_dump.  Variable setting to allow replacement of variable values at runtime.  The single best way to troubleshoot bugs. 
  • 8. Xdebug Profiling Find bottlenecks  Timings for optimization  Similar to Cachegrind but no memory data  Output format is standard so it can be read by standard Cachegrind tools: Kcachegrind, QCacheGrind, WinCacheGrind, IDE plugins, etc. 
  • 9. Xdebug Requirements  Installing the Xdebug extension  PEAR/PECL install available  Available via most Linux package managers DBGP client for remote debugging – Debugclient comes with Xdebug source and a slew of IDEs have built in support.  Cachegrind analyzer for profiling – KCachegrind, QCachegrind, WinCacheGrind, or IDE support. 
  • 10. Remote Debug Configuration extended_info – Enabled by default. Allows breakpoints.  idekey – Identifier for the debug session. Most clients will restrict to requests from a single idekey value.  remote_autostart – Disabled by default. Will start remote debugging with every request. 
  • 11. Remote Debug Configuration remote_connect_back – Disabled by default. Helpful for debugging on shared hosts and virtual machines. Xdebug session will connect to host making the request.  remote_cookie_expire_time – Defaults to 3600 seconds (60 minutes). The time the debug session cookie will live. 
  • 12. Remote Debug Configuration remote_enable – Defaults to 0 (off). Enable remote debugging  remote_handler – Defaults to DBGP. You should never have to use anything else so just leave it.  remote_host – Remote host with which Xdebug will connect at the start of an Xdebug session. 
  • 13. Remote Debug Configuration remote_log – Default value “”. Log all remote debugger communication. You will probably never need this unless you are writing a client or have connectivity issues.  remote_mode – Default value is “req”. Determines how the session is initiated. “req” will start the session with every request. “jit” will start the session when an error condition occurs. 
  • 14. Remote Debug Configuration  remote_port – Defaults to 9000. TCP/IP port of the remote client which which Xdebug will connect. Most clients default to 9000 so unless you are forced to debug multiple remote machines, just leave it.
  • 15. Profiling Configuration profiler_append – Default value 0 (off). Append the profiler output to the same file if the profile_output_name will allow.  profiler_enable – Default value 0 (off). Enable profiling for all requests and script executions. If you are doing web request profiling, use profiler_enable_trigger instead. This should normally be used only for CLI profiling and configuring via environment variable. 
  • 16. Profiling Configuration profiler_enable_trigger – Default value 0 (off). Allow triggering of profiling via request query parameter or cookie with the name XDEBUG_PROFILE. The value is optional and ignored.  profiler_output_dir – Defaults to “/tmp”. The directory in which the profiler output file will be written. 
  • 17. Profiling Configuration  profiler_output_name – Default value is “cachegrind.out.%p” where %p is the process ID of the process running the profile. There are many variable options like %s for the file name. See the Xdebug documentation for details: http://xdebug.org/docs/all_settings#trace _output_name
  • 18. Configuring via php.ini Always prepend option with “xdebug.” Example: zend_extension=/usr/local/php/modules/xd ebug.so xdebug.remote_enable=1 xdebug.remote_connect_back=1 xdebug.profiler_enable_trigger=1
  • 19. Configuring via .htaccess If you have no other options, you can use a .htaccess file if allowed. Example: php_flag xdebug.remote_enable true php_value xdebug.remote_host “10.0.0.2” php_flag xdebug.profiler_enable_trigger true
  • 20. Configuring via environment  When running CLI scripts, you can configure Xdebug via the XDEBUG_CONFIG variable Profiling Example: export XDEBUG_CONFIG=“profiler_enable=1” Remote Debugging Example: export XDEBUG_CONFIG=“idekey=key”
  • 21. Start/Stop Xdebug Sessions You can start and stop Xdebug remote debugging and profiling sessions in many ways:  IDE integration  Browser Plugin (Chrome/Firefox/Safari)  URL parameter  Cookie  CLI environment variable  Xdebug config
  • 22. Start/Stop via IDE Most IDEs will have a way to start a remote debug or profiling session from the command line or web page.  See the documentation for your IDE to learn how to use that. 
  • 23. Start/Stop via Browser Plugin Browser plugins are a nice simple way to start and stop an Xebug session  Available for most browsers.  Will automatically (un)set the XDEBUG_SESSION or XDEBUG_PROFILE cookie. 
  • 24. Start/Stop via URL Parameter XDEBUG_SESSION_START=idekey  XDEBUG_SESSION_STOP  XDEBUG_PROFILE  Example: http://site.com?XDEBUG_SESSION_START=go http://site.com?XDEBUG_SESSION_STOP http://site.com?XDEBUG_PROFILE
  • 25. Start/Stop via Cookie Use a cookie named XDEBUG_SESSION with the value being the idekey value. Remote Debug Example: curl --cookie=“XDEBUG_SESSION=eclipse” http://host.com Profiling Example: curl --cookie=“XDEBUG_PROFILE=1” http://host.com
  • 26. Start/Stop via CLI Environment   XDEBUG_CONFIG environment variable will start stop CLI Xdebug for profiling and debugging Can be executed for a single script or multiple scripts Multi-Command Example: export XDEBUG_CONFIG=“remote_host=localhost” php script.php export XDEBUG_CONFIG= Single Command Example: XDEBUG_CONFIG=“profiler_enable=1” php script.php
  • 27. Start/Stop via Xdebug Config Setting xebug.remote_autostart will start remote debugging with every execution.  Setting xdebug.profiler_enable will start profiling with every execution.  Requires config change to turn off.  Try and avoid this. There are so many better ways. 
  • 28. Demo Here we go with some code and examples.