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.

Use Xdebug to profile PHP

Presentation from webinar held on August 19th, 2020, with Xdebug developer Derick Rethans and Seravo CEO Otto Kekäläinen.

This presentation shows you how to use Xdebug (which is very easy with the Seravo WordPress development environment!) to make a record of what the WordPress PHP code does during a website page load, and how to use that information to optimize the performance of your WordPress site.

For a video recording and Dericks presentation see https://seravo.com/blog/webinar-xdebug-profile-php/

  • Entre para ver os comentários

Use Xdebug to profile PHP

  1. 1. Use Xdebug to profile PHP
  2. 2. Premium hosting and upkeep for WordPress HTTP/2 TESTED UPDATES 24/7 UPKEEP
  3. 3. Top-notch performance A comparison published by a Google employee at ismyhostfastyet.com confirms that Seravo’s customer sites load faster than competing services’. The study used time-to-first-byte (TTFB) measurement data from real users as collected from the Chrome browser UX data. Fast/Average/Slow TTFB by WordPress Host
  4. 4. Seravo recommends Xdebug ● Xdebug is open source: github.com/xdebug/xdebug ● Embraced by the PHP community ● Plenty of features: profiling, stack traces, debugging.. ● Included in Linux distributions, easy to install ● Pre-installed in many development environments ○ Varying Vagrant Vagrants (for WordPress core contributors) ■ xdebug_on ○ Seravo WordPress Vagrant and Docker images (for Seravo’s customers) ■ wp-xdebug-on
  5. 5. What on earth is PHP doing?! Finding the code bottlenecks is hard without proper tools. Solution: ● Profile PHP code with Xdebug ● Browse results with Webgrind ● Visualize code path with Gprof2dot and Dot
  6. 6. All WordPress site developers should learn Xdebug It is easy!
  7. 7. Very easy with Seravo WordPress dev ● Enable by running: wp-xdebug-on ● Run profiler on any URL easily by appending one parameter ○ E.g. https://wordpress.local/?XDEBUG_PROFILE ● Files are generated at /tmp/cachegrind.out.x.y.z ● Browse results with Webgrind ○ E.g. http://wordpress.local/.seravo/webgrind/ Documentation at seravo.com/docs/development/xdebug/
  8. 8. DEMO
  9. 9. Typical issues: database Typically developers don’t test their plugins with large amounts of data and they work well on small sites. As sites grow, all problems related to excess data manipulation become visible. Solution: ● Inject more data on a test site and see how it behaves. ● In code, don’t fetch everything from the database. Remember LIMIT in SQL and posts_per_page in WP_Query. ● Design code to fetch only what is needed for the view, nothing else.
  10. 10. Switch to Polylang for faster page loads
  11. 11. Typical issues: HTTP requests External API calls in PHP typically also block the entire site from loading if the external API is down. Solution: ● Review use of wp_remote_get(), fopen() and similar ● Store result and avoid re-fetching it all the time using WP Transients API
  12. 12. Use WP Transients API Store the result of a heavy/slow computation to avoid having to do it all the time (e.g. HTTP requests or heavy database queries): More at: seravo.com/blog/faster-wordpress-with-transients/ and developer.wordpress.org/apis/handbook/transients/
  13. 13. Extra helper: wp-speed-test vagrant@development:~$ wp-speed-test Testing speed URL https://wordpress.local... For an explanation of the different times, please see docs at https://curl.haxx.se/docs/manpage.html URL TOTAL NAMELOOKUP CONNECT APPCONNECT PRETRANSFER STARTTRANSFER = AVG https://wordpress.local 0.179 0.004 0.004 0.014 0.014 0.179 0.179 https://wordpress.local 0.154 0.000 0.000 0.000 0.000 0.154 0.167 https://wordpress.local 0.157 0.000 0.000 0.000 0.000 0.157 0.164 https://wordpress.local 0.167 0.000 0.000 0.000 0.000 0.167 0.164 https://wordpress.local 0.163 0.000 0.000 0.000 0.000 0.162 0.169 https://wordpress.local 0.147 0.000 0.000 0.000 0.000 0.147 0.168 https://wordpress.local 0.169 0.000 0.000 0.000 0.000 0.169 0.168 https://wordpress.local 0.178 0.000 0.000 0.000 0.000 0.178 0.168 https://wordpress.local 0.167 0.000 0.000 0.000 0.000 0.167 0.168 Test completed. If the values seems too high, please profile your PHP code to find potential bottlenecks. Note that this test tells how fast your site is in the sense of how long it takes for PHP to generate the HTML output. To test how much load the site can handle, run wp-load-test.
  14. 14. Hunt for random slowness $ wp-speed-test https://wordpress.local/hello-world/?XDEBUG_PROFILE Testing speed URL https://wordpress.local/hello-world/?XDEBUG_PROFILE... For an explanation of the different times, please see docs at https://curl.haxx.se/docs/manpage.html URL TOTAL NAMELOOKUP CONNECT APPCONNECT PRETRANSFER STARTTRANSFER = AVG https://wordpress.local/hel... 0.637 0.004 0.004 0.013 0.013 0.636 0.637 https://wordpress.local/hel... 0.469 0.000 0.000 0.000 0.000 0.468 0.553 https://wordpress.local/hel... 0.512 0.000 0.000 0.000 0.000 0.511 0.539 https://wordpress.local/hel... 0.484 0.000 0.000 0.000 0.000 0.483 0.525 https://wordpress.local/hel... 0.483 0.000 0.000 0.000 0.000 0.482 0.517 https://wordpress.local/hel... 0.556 0.000 0.000 0.000 0.000 0.555 0.524 https://wordpress.local/hel... 0.910 0.000 0.000 0.000 0.000 0.908 0.640 https://wordpress.local/hel... 0.496 0.000 0.000 0.000 0.000 0.495 0.633 https://wordpress.local/hel... 0.475 0.000 0.000 0.000 0.000 0.474 0.625 16 MB
  15. 15. Always remember to measure before and after!
  16. 16. seravo.com/docs Instructions for WordPress site developers
  17. 17. Lots of tips out there! The database is often the performance bottleneck. See my other talk on WordPress and database optimization: More in-depth code profiling tips in my WordPress performance talk: wordpress.tv/?s=otto+kekäläinen
  18. 18. See also Make Your Site Faster with Caching https://seravo.com/blog/wordpress-cache/ 300% faster WordPress load times with transients https://seravo.com/blog/faster-wordpress-with-transients/ 5 common reasons why your WordPress site is slow https://youtu.be/8sJExUO-U4A Improving WordPress Performance with XDebug and PHP Profiling https://youtu.be/oKcIS5A-6_c
  19. 19. Thank you! Seravo.com @Seravo @ottokekalainen

×