Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
IMPROVING
WORDPRESS
PERFORMANCE
XDebug and PHP profiling
WordCamp Europe 2017
Otto Kekäläinen
Seravo.com
@ottokekalainen
● Linux and open source advocate
● Contributed to WordPress Core,
translations, Linux, Docker,
Nginx, Redis, MariaDB…
● CE...
Enterprise grade
hosting and upkeep
for WordPress
WORDPRESS SUCCESS FACTORS
1. Easy to use
2. Easy to extend
COMMON CHALLENGES
1. Security
2. Speed
A WEB FULL OF WRONG ADVICE
Most of the guides and tutorials on
security and speed lack evidence.
I’ve done mythbusting at many WordCamps with
WordPress Security 101
seravo.com/wordpress-security-101/
Now it is time to make sense out of
WordPress Speed
Performance
STEP 1: Measure
STEP 2: Optimize
STEP 3: Validate
STEP 4: Rinse and repeat
STEP 1: Measure
Find out your baseline to make sure your
optimizations later at least do not worsen
the performance!
FULL PAGE LOAD
● Online tools
○ WebPageTest.org
○ GTMetrix.com
○ Pingdom Tools
○ Yellow Lab Tools
○ Pagelocity
○ KeyCDN Pe...
HOW FAST IS WORDPRESS?
= How fast PHP code generates the HTML
= HTTP request time
CURL
ssh example.com
curl -s -o /dev/null 
-w "%{time_total}n" https://example.com/
0,235
https://curl.haxx.se/docs/manpag...
CURL WITH NO CACHE
curl -s -o /dev/null 
-w "%{time_total}n" 
-H "Pragma: no-cache" https://example.com/
https://developer...
CURL LOOP TO DETECT VARIATION
export LC_NUMERIC=C
for i in {1..20}
do
curl -so /dev/null -w "%{time_total}n" http://localh...
LOG HTTP REQUEST TIME
[29/May/2017:10:02:45 +0300] "POST /wp-admin/admin-ajax.php
HTTP/1.1" 200 58 "Mozilla/5.0 (KHTML, li...
ANALYZE WITH GOACCESS
➔ Average load time
➔ Cumulative load time
= sum of all loads
STEP 2: Optimize
Find and solve the bottleneck
QUICK AND DIRTY: WP-CLI LOOP
for p in $(wp plugin list --fields=name --status=active)
do
echo $p
wp plugin deactivate $p
f...
QUICK AND DIRTY: WP-CLI LOOP
● Baseline ~550 ms
● Deactivating
wp-to-twitter or
polylang does not have
an effect
● When de...
A LITTLE MORE DEPTH: DEBUG BAR
THE PROFESSIONAL WAY: XDEBUG
A tool for developers to
● analyze PHP
execution
● find bottle necks
● xdebug.org
XDEBUG INSTALLATION
$ sudo apt-get install php-xdebug
$ nano /etc/php/fpm/conf.d/20-xdebug.ini
; Enable xdebug
zend_extens...
PROFILING RUN OF WORDPRESS
FRONT PAGE
/tmp $ curl -I http://localhost/?XDEBUG_PROFILE=1 
-w "%{time_total}n"
0.611
/tmp $ ...
WEBGRIND INSTALLATION
$ cd /data/wordpress/htdocs
$ git clone https://github.com/jokkedk/webgrind
$ sudo apt-get install g...
PREINSTALLED IN VVV AND
SERAVO VAGRANT
laptop$ vagrant ssh
vagrant$ xdebug_on # Varying Vagrant Vagrants
vagrant$ wp-xdebu...
Go profiling!
WEBGRIND UI EXPLAINED
FILTER FOR USUAL SUSPECTS
● load
● open
● curl
● query
SHOW CALL GRAPH
UNDERSTAND
THE CODE
FLOW
Typical issues and
solutions
FREQUENT OR LONG DB QUERIES?
Fix Avada theme
upgrade check
WPML?
SWITCH
TO
POLYLANG
EXTERNAL HTTP REQUESTS ON
EVERY PAGE LOAD?
DEVELOPERS: PLEASE LEARN TO
USE THE WP TRANSIENT API!
Most DB queries and external PHP::curl request can be cached easily:
Hunt down that
rare beast
$ for i in {1..99};
do curl -IL -H "Pragma: no-cache"
-w "%{time_total}n" -o /dev/null
-s "http://localhost/?XDEBUG_PROFIL...
STEP 3: Validate
STEP 4: Rinse & repeat
DEMO: How fast can we make
Twentyseventeen?
STEP 1: MEASURE
STEP 2: OPTIMIZE
Translation functions slowest. WP does not use native
gettext (https://core.trac.wordpress.org/ticket/172...
STEP 3: VALIDATE
Before: 500-600 ms After: 300-400 ms
SEE IT YOURSELF!
wceu2017-demo.seravo.com
wceu2017-demo.seravo.com/webgrind
github.com/ottok/wceu2017-demo
REMEMBER
● Nginx access logs easy
● Xdebug never in production
● xhprof/uprofiler can be production
● PCEL APD (2004)
● me...
THANK YOU!
SERAVO.COM
facebook.com/Seravocom
Twitter: @Seravo @ottokekalainen
Upcoming SlideShare
Loading in …5
×

of

Improving WordPress Performance with Xdebug and PHP Profiling Slide 1 Improving WordPress Performance with Xdebug and PHP Profiling Slide 2 Improving WordPress Performance with Xdebug and PHP Profiling Slide 3 Improving WordPress Performance with Xdebug and PHP Profiling Slide 4 Improving WordPress Performance with Xdebug and PHP Profiling Slide 5 Improving WordPress Performance with Xdebug and PHP Profiling Slide 6 Improving WordPress Performance with Xdebug and PHP Profiling Slide 7 Improving WordPress Performance with Xdebug and PHP Profiling Slide 8 Improving WordPress Performance with Xdebug and PHP Profiling Slide 9 Improving WordPress Performance with Xdebug and PHP Profiling Slide 10 Improving WordPress Performance with Xdebug and PHP Profiling Slide 11 Improving WordPress Performance with Xdebug and PHP Profiling Slide 12 Improving WordPress Performance with Xdebug and PHP Profiling Slide 13 Improving WordPress Performance with Xdebug and PHP Profiling Slide 14 Improving WordPress Performance with Xdebug and PHP Profiling Slide 15 Improving WordPress Performance with Xdebug and PHP Profiling Slide 16 Improving WordPress Performance with Xdebug and PHP Profiling Slide 17 Improving WordPress Performance with Xdebug and PHP Profiling Slide 18 Improving WordPress Performance with Xdebug and PHP Profiling Slide 19 Improving WordPress Performance with Xdebug and PHP Profiling Slide 20 Improving WordPress Performance with Xdebug and PHP Profiling Slide 21 Improving WordPress Performance with Xdebug and PHP Profiling Slide 22 Improving WordPress Performance with Xdebug and PHP Profiling Slide 23 Improving WordPress Performance with Xdebug and PHP Profiling Slide 24 Improving WordPress Performance with Xdebug and PHP Profiling Slide 25 Improving WordPress Performance with Xdebug and PHP Profiling Slide 26 Improving WordPress Performance with Xdebug and PHP Profiling Slide 27 Improving WordPress Performance with Xdebug and PHP Profiling Slide 28 Improving WordPress Performance with Xdebug and PHP Profiling Slide 29 Improving WordPress Performance with Xdebug and PHP Profiling Slide 30 Improving WordPress Performance with Xdebug and PHP Profiling Slide 31 Improving WordPress Performance with Xdebug and PHP Profiling Slide 32 Improving WordPress Performance with Xdebug and PHP Profiling Slide 33 Improving WordPress Performance with Xdebug and PHP Profiling Slide 34 Improving WordPress Performance with Xdebug and PHP Profiling Slide 35 Improving WordPress Performance with Xdebug and PHP Profiling Slide 36 Improving WordPress Performance with Xdebug and PHP Profiling Slide 37 Improving WordPress Performance with Xdebug and PHP Profiling Slide 38 Improving WordPress Performance with Xdebug and PHP Profiling Slide 39 Improving WordPress Performance with Xdebug and PHP Profiling Slide 40 Improving WordPress Performance with Xdebug and PHP Profiling Slide 41 Improving WordPress Performance with Xdebug and PHP Profiling Slide 42 Improving WordPress Performance with Xdebug and PHP Profiling Slide 43 Improving WordPress Performance with Xdebug and PHP Profiling Slide 44 Improving WordPress Performance with Xdebug and PHP Profiling Slide 45 Improving WordPress Performance with Xdebug and PHP Profiling Slide 46 Improving WordPress Performance with Xdebug and PHP Profiling Slide 47
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

11 Likes

Share

Download to read offline

Improving WordPress Performance with Xdebug and PHP Profiling

Download to read offline

Presentation given at WordCamp Europe 2017 in Paris 2017-06-16.

Xdebug is a tool for developers to gain insight into how PHP is executed. Using it for profiling is a very effective, fast and precise method to find bottlenecks in your WordPress site. In this talk I explain how to use it with Webgrind, how to find potential optimization targets, show examples of real cases when Xdebug helped fix a performance problem and also explain what Xdebug is not suitable for and what can be used instead. If you are not a developer, you’ll learn what Xdebug is capable of and when to ask a developer to use it.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Improving WordPress Performance with Xdebug and PHP Profiling

  1. 1. IMPROVING WORDPRESS PERFORMANCE XDebug and PHP profiling WordCamp Europe 2017 Otto Kekäläinen Seravo.com @ottokekalainen
  2. 2. ● Linux and open source advocate ● Contributed to WordPress Core, translations, Linux, Docker, Nginx, Redis, MariaDB… ● CEO, sysadmin and developer at Seravo.com – WordPress hosting and upkeep Otto Kekäläinen
  3. 3. Enterprise grade hosting and upkeep for WordPress
  4. 4. WORDPRESS SUCCESS FACTORS 1. Easy to use 2. Easy to extend
  5. 5. COMMON CHALLENGES 1. Security 2. Speed
  6. 6. A WEB FULL OF WRONG ADVICE Most of the guides and tutorials on security and speed lack evidence.
  7. 7. I’ve done mythbusting at many WordCamps with WordPress Security 101 seravo.com/wordpress-security-101/
  8. 8. Now it is time to make sense out of WordPress Speed Performance
  9. 9. STEP 1: Measure STEP 2: Optimize STEP 3: Validate STEP 4: Rinse and repeat
  10. 10. STEP 1: Measure Find out your baseline to make sure your optimizations later at least do not worsen the performance!
  11. 11. FULL PAGE LOAD ● Online tools ○ WebPageTest.org ○ GTMetrix.com ○ Pingdom Tools ○ Yellow Lab Tools ○ Pagelocity ○ KeyCDN Performance Test ○ … ● Visualize: ○ HTML load time ○ CSS rendering ○ JavaScript loading ○ image files download ○ …
  12. 12. HOW FAST IS WORDPRESS? = How fast PHP code generates the HTML = HTTP request time
  13. 13. CURL ssh example.com curl -s -o /dev/null -w "%{time_total}n" https://example.com/ 0,235 https://curl.haxx.se/docs/manpage.html#-w
  14. 14. CURL WITH NO CACHE curl -s -o /dev/null -w "%{time_total}n" -H "Pragma: no-cache" https://example.com/ https://developers.google.com/web/fundamentals/performance/opti mizing-content-efficiency/http-caching
  15. 15. CURL LOOP TO DETECT VARIATION export LC_NUMERIC=C for i in {1..20} do curl -so /dev/null -w "%{time_total}n" http://localhost/ done | awk '{ sum += $1; n++; print $1 } END { if (n > 0) print "AVG: " sum / n; }' 0.209 0.107 0.152 AVG: 0.1378
  16. 16. LOG HTTP REQUEST TIME [29/May/2017:10:02:45 +0300] "POST /wp-admin/admin-ajax.php HTTP/1.1" 200 58 "Mozilla/5.0 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" - - 0.028 nginx.conf log_format extensive '$host ' '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" ' '$upstream_cache_status - ' '$request_time';
  17. 17. ANALYZE WITH GOACCESS ➔ Average load time ➔ Cumulative load time = sum of all loads
  18. 18. STEP 2: Optimize Find and solve the bottleneck
  19. 19. QUICK AND DIRTY: WP-CLI LOOP for p in $(wp plugin list --fields=name --status=active) do echo $p wp plugin deactivate $p for i in {1..5} do curl -so /dev/null -w "%{time_total}n" -H "Pragma: no-cache" http://localhost/ done wp plugin activate $p done
  20. 20. QUICK AND DIRTY: WP-CLI LOOP ● Baseline ~550 ms ● Deactivating wp-to-twitter or polylang does not have an effect ● When deactivating advanced-custom-fields -pro load times drop to ~65 ms
  21. 21. A LITTLE MORE DEPTH: DEBUG BAR
  22. 22. THE PROFESSIONAL WAY: XDEBUG A tool for developers to ● analyze PHP execution ● find bottle necks ● xdebug.org
  23. 23. XDEBUG INSTALLATION $ sudo apt-get install php-xdebug $ nano /etc/php/fpm/conf.d/20-xdebug.ini ; Enable xdebug zend_extension=xdebug.so ; Enable php profiling with get param XDEBUG_PROFILE=1 xdebug.profiler_output_dir=/tmp xdebug.profiler_output_name=cachegrind.out.%t.%p xdebug.profiler_enable_trigger=1 $ sudo service restart php-fpm
  24. 24. PROFILING RUN OF WORDPRESS FRONT PAGE /tmp $ curl -I http://localhost/?XDEBUG_PROFILE=1 -w "%{time_total}n" 0.611 /tmp $ ll -h 11M cachegrind.out.1455198789.5601 /tmp $ head cachegrind.out.1455198789.5601 version: 1 creator: xdebug 2.2.3 cmd: /data/wordpress/htdocs/index.php part: 1 positions: line ...
  25. 25. WEBGRIND INSTALLATION $ cd /data/wordpress/htdocs $ git clone https://github.com/jokkedk/webgrind $ sudo apt-get install graphviz
  26. 26. PREINSTALLED IN VVV AND SERAVO VAGRANT laptop$ vagrant ssh vagrant$ xdebug_on # Varying Vagrant Vagrants vagrant$ wp-xdebug-on # Seravo Vagrant
  27. 27. Go profiling!
  28. 28. WEBGRIND UI EXPLAINED
  29. 29. FILTER FOR USUAL SUSPECTS ● load ● open ● curl ● query
  30. 30. SHOW CALL GRAPH
  31. 31. UNDERSTAND THE CODE FLOW
  32. 32. Typical issues and solutions
  33. 33. FREQUENT OR LONG DB QUERIES? Fix Avada theme upgrade check
  34. 34. WPML? SWITCH TO POLYLANG
  35. 35. EXTERNAL HTTP REQUESTS ON EVERY PAGE LOAD?
  36. 36. DEVELOPERS: PLEASE LEARN TO USE THE WP TRANSIENT API! Most DB queries and external PHP::curl request can be cached easily:
  37. 37. Hunt down that rare beast
  38. 38. $ for i in {1..99}; do curl -IL -H "Pragma: no-cache" -w "%{time_total}n" -o /dev/null -s "http://localhost/?XDEBUG_PROFILE=1"; done $ ll -Sh /tmp -rw-r--r-- 111M cachegrind.out.1455200976.5601 -rw-r--r-- 91M cachegrind.out.1455200984.5601 -rw-r--r-- 89M cachegrind.out.1455200972.5604 -rw-r--r-- 89M cachegrind.out.1455200964.5604 -rw-r--r-- 88M cachegrind.out.1455200973.5604 -rw-r--r-- 87M cachegrind.out.1455200963.5601 -rw-r--r-- 87M cachegrind.out.1455200967.5601
  39. 39. STEP 3: Validate
  40. 40. STEP 4: Rinse & repeat
  41. 41. DEMO: How fast can we make Twentyseventeen?
  42. 42. STEP 1: MEASURE
  43. 43. STEP 2: OPTIMIZE Translation functions slowest. WP does not use native gettext (https://core.trac.wordpress.org/ticket/17268). Solution: composer require aucor/dynamic-mo-loader
  44. 44. STEP 3: VALIDATE Before: 500-600 ms After: 300-400 ms
  45. 45. SEE IT YOURSELF! wceu2017-demo.seravo.com wceu2017-demo.seravo.com/webgrind github.com/ottok/wceu2017-demo
  46. 46. REMEMBER ● Nginx access logs easy ● Xdebug never in production ● xhprof/uprofiler can be production ● PCEL APD (2004) ● memory_get_usage(), microtime()
  47. 47. THANK YOU! SERAVO.COM facebook.com/Seravocom Twitter: @Seravo @ottokekalainen
  • melbagnato

    Feb. 15, 2020
  • SiriusNottin

    Aug. 6, 2019
  • hizw

    Jul. 26, 2018
  • alexminza

    Feb. 11, 2018
  • asheboro

    Jan. 4, 2018
  • JanezSvetin

    Jun. 16, 2017
  • FrankBltge1

    Jun. 16, 2017
  • ElliottRichmond

    Jun. 16, 2017
  • kOoLiNuS

    Jun. 16, 2017
  • robewilde

    Jun. 16, 2017
  • nordstrandqueen

    Jun. 16, 2017

Presentation given at WordCamp Europe 2017 in Paris 2017-06-16. Xdebug is a tool for developers to gain insight into how PHP is executed. Using it for profiling is a very effective, fast and precise method to find bottlenecks in your WordPress site. In this talk I explain how to use it with Webgrind, how to find potential optimization targets, show examples of real cases when Xdebug helped fix a performance problem and also explain what Xdebug is not suitable for and what can be used instead. If you are not a developer, you’ll learn what Xdebug is capable of and when to ask a developer to use it.

Views

Total views

10,009

On Slideshare

0

From embeds

0

Number of embeds

3,539

Actions

Downloads

67

Shares

0

Comments

0

Likes

11

×