2. Xdebug is an extension for PHP to assist with debugging and
development.
it upgrades PHP's var_dump() function; it adds stack traces
for Notices, Warnings, Errors and Exceptions
What is XDebug?
• Debugging
• Stack Tracing
• Profiling
@Kayleighthorpe
3. Installation
https://xdebug.org/docs/install
Most installations require downloading the XDebug package
and enabling it within your php.ini file
XDebug is an advanced tool and can only be installed if you have server
side access or your hosting provider installs it for you.
@Kayleighthorpe
9. [root@34SP:.../albinofruit.com/statistics/logs]$ tail -n50 php-error.log
[06-Apr-2018 13:37:55 UTC] PHP Warning: count(): Parameter must be
an array or an object that implements Countable in
/var/www/vhosts/albinofruit.com/httpdocs/wp-content/plugins/simple-
lightbox/includes/class.utilities.php on line 1411
[root@34SP:.../albinofruit.com/statistics/logs]$
Basic error log example:
Shows a warning, nothing breaking the site currently, but it might
cause problems in newer PHP versions or the error might slow my
site down.
@Kayleighthorpe
10. [06-Apr-2018 13:37:55 UTC] PHP Warning: count(): Parameter must be an array or an object that
implements Countable in /var/www/vhosts/albinofruit.com/httpdocs/wp-content/plugins/simple-
lightbox/includes/class.utilities.php on line 1411
[06-Apr-2018 13:37:55 UTC] PHP Stack trace:
[06-Apr-2018 13:37:55 UTC] PHP 1. {main}() /var/www/vhosts/albinofruit.com/httpdocs/wp/wp-
admin/options-general.php:0
[06-Apr-2018 13:37:55 UTC] PHP 2. require_once() /var/www/vhosts/albinofruit.com/httpdocs/wp/wp-
admin/options-general.php:10
[06-Apr-2018 13:37:55 UTC] PHP 3. require_once() /var/www/vhosts/albinofruit.com/httpdocs/wp/wp-
admin/admin.php:216
[06-Apr-2018 13:37:55 UTC] PHP 4. do_action() /var/www/vhosts/albinofruit.com/httpdocs/wp/wp-
admin/admin-header.php:97
[06-Apr-2018 13:37:55 UTC] PHP 5. WP_Hook->do_action()
/var/www/vhosts/albinofruit.com/httpdocs/wp/wp-includes/plugin.php:453
[06-Apr-2018 13:37:55 UTC] PHP 6. WP_Hook->apply_filters()
/var/www/vhosts/albinofruit.com/httpdocs/wp/wp-includes/class-wp-hook.php:310
[06-Apr-2018 13:37:55 UTC] PHP 7. SLB_Admin->enqueue_client_files()
/var/www/vhosts/albinofruit.com/httpdocs/wp/wp-includes/class-wp-hook.php:284
[06-Apr-2018 13:37:55 UTC] PHP 8. SLB_Utilities->is_context()
/var/www/vhosts/albinofruit.com/httpdocs/wp-content/plugins/simple-lightbox/includes/class.base.php:365
[06-Apr-2018 13:37:55 UTC] PHP 9. SLB_Utilities->get_context()
/var/www/vhosts/albinofruit.com/httpdocs/wp-content/plugins/simple-
lightbox/includes/class.utilities.php:996
[06-Apr-2018 13:37:55 UTC] PHP 10. SLB_Utilities->get_action()
/var/www/vhosts/albinofruit.com/httpdocs/wp-content/plugins/simple-
lightbox/includes/class.utilities.php:921
Stack Tracing
Same log with XDebug enabled:
Loads everything in order @Kayleighthorpe
12. To view cachegrind file you can use:
Webgrind: https://github.com/jokkedk/webgrind
Or:
brew install qcachegrind
brew install graphviz
Qcachegrind:
On Mac
@Kayleighthorpe
qcachegrind ~/Downloads/cachegrind.out.21991
name is kayleigh
From 34SP
MANCHESTER
today talking about a tool really useful called xdebug
module you can install on web server
Extends PHP's var_dump
Adds stack tracing and profiling which helps find bugs and boost performance
need server side access
Would read recommend local environment as resource intensive and can slow live sites down
Will show on my web server but showing how easy it is to get started on local environment
Mamp for Mac
Program to create local dev sites
Easy to set up, just download and install
Press start server to begin developing a local site on your computer you can upload later
When MAMP is set up get this screen
To enable xdebug
Check phpinfo to find where our php.ini config file is
Shows me where my php.ini is
Open that, the bottom line has xdebug extension commented out
Uncomment to enable and set the xdebug settings you want to use
Available settings in documentation link I will show at the end
Will need to restart the web server Check xdebug is enabled by going back to phpinfo
I'm also enabling on site errors here just to show you it working on MAMP
This is my local environments home page, purposely created a PHP error just to show you how it looks on site, you don't have to display errors on sight you can just put them in a log file which is less intrusive
Example of stack tracing - here's what my web servers error log looks like without xdebug
Basic error information
With xdebug, shows the full stack trace and I can pinpoint where errors occur easier
Profiling also useful tool for finding performance issues
Profile takes a bunch of information from your initiated php code and puts it in a file called cachegrind
Enable profiling and setting where to put cachegrind file - pretty unreadable
Can read cachegrind file using a program - webgeind is popular but I'm showing qcachegrind because it's the easiest to set up on mac
Gives visual representation of your php functions and execution times so you can pick up where issues lie easier
Full screen of left panel - lists functions in order of time taken to run so for example if you see a plugins function takin forever in here you know it's a culprit for slowing things down - useful
Reason use on development site is its resource intensive, constantly checking things when it's enabled, so remember to switch off if running on live servers
Here's the link to docs so you can find out more about installing and debugging using this pretty great took