O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

An Introduction to Xdebug for WordPress

A short guide to getting started with XDebug, setting up locally and using it to debug WordPress issues.

  • Entre para ver os comentários

  • Seja a primeira pessoa a gostar disto

An Introduction to Xdebug for WordPress

  1. 1. XDebug @Kayleighthorpe Introducing my friend
  2. 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. 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
  4. 4. MAMP Download and Install MAMP: https://www.mamp.info/en/ Start server @Kayleighthorpe
  5. 5. @Kayleighthorpe MAMP Use phpinfo to find out where your PHP.ini is: MAMP
  6. 6. @Kayleighthorpe MAMPMAMP Open PHP.ini and this will be at the bottom of the file: Uncomment to enable and add the following options:
  7. 7. MAMP @Kayleighthorpe Check Debug is enabled in php.ini: Optional: Enable display errors:
  8. 8. @Kayleighthorpe MAMPMAMP
  9. 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. 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
  11. 11. Profiling php_value[xdebug.profiler_enable]=1 php_value[xdebug.profiler_output_dir]=/var/www/vhosts/theresite.c o.uk/httpdocs/ Creates a cachegrind file You can cat the file, but it’ll not make a lot of sense. Helps to find out where memory issues lie, by saving data about your called functions in a cachegrind file. @Kayleighthorpe
  12. 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
  13. 13. @Kayleighthorpe Displays how long individual functions take to run.
  14. 14. @Kayleighthorpe
  15. 15. Keep Debug switched off unless it is being used. @Kayleighthorpe Run on development site.
  16. 16. https://xdebug.org/docs/ @Kayleighthorpe
  17. 17. Thank You @Kayleighthorpe

×