SlideShare a Scribd company logo
IMPROVING
WORDPRESS
PERFORMANCE
Xdebug and PHP profiling
WordCamp Athens 2017
Otto Kekäläinen
Seravo.com
@ottokekalainen
● 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
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 Performance Test
○ …
● Visualize:
○ HTML load time
○ CSS rendering
○ JavaScript loading
○ image files download
○ …
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/manpage.html#-w
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
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
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';
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
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
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
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_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
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
...
WEBGRIND INSTALLATION
$ cd /data/wordpress/htdocs
$ git clone https://github.com/jokkedk/webgrind
$ sudo apt-get install graphviz
PREINSTALLED IN VVV AND
SERAVO VAGRANT
laptop$ vagrant ssh
vagrant$ xdebug_on # Varying Vagrant Vagrants
vagrant$ wp-xdebug-on # Seravo Vagrant
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
SWITCH
TO
POLYLANG
FOR FASTER
PAGE LOADS
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_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
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/17268).
Solution:
composer require aucor/dynamic-mo-loader
STEP 3: VALIDATE
Before: 500-600 ms After: 300-400 ms
SEE IT YOURSELF!
github.com/ottok/wceu2017-demo
REMEMBER
● Nginx access logs easy
● Xdebug never in production
● xhprof/uprofiler can be production
● PCEL APD (2004)
● memory_get_usage(), microtime()
THANK YOU!
SERAVO.COM
facebook.com/Seravocom
Twitter: @Seravo @ottokekalainen

More Related Content

PDF
Automatic testing and quality assurance for WordPress plugins
PDF
Improving WordPress Performance with Xdebug and PHP Profiling
PDF
How to investigate and recover from a security breach in WordPress
PDF
Seravo.com: WordPress Security 101
PDF
Use Xdebug to profile PHP
PDF
10 things every developer should know about their database to run word press ...
PDF
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
PDF
Less and faster – Cache tips for WordPress developers
Automatic testing and quality assurance for WordPress plugins
Improving WordPress Performance with Xdebug and PHP Profiling
How to investigate and recover from a security breach in WordPress
Seravo.com: WordPress Security 101
Use Xdebug to profile PHP
10 things every developer should know about their database to run word press ...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
Less and faster – Cache tips for WordPress developers

What's hot (20)

PDF
Search in WordPress - how it works and howto customize it
PPTX
Improving WordPress Performance: Xdebug and PHP profiling
PPTX
Xdebug, KCacheGrind and Webgrind with WampServer
PDF
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
PPTX
Anthony Somerset - Site Speed = Success!
PDF
Developers, Be a Bada$$ with WP-CLI
PPTX
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
PPTX
Grunt and Bower
PDF
WordPress Performance optimization
PPTX
My Database Skills Killed the Server
PDF
Running and Scaling Magento on AWS
PDF
Single page apps with drupal 7
PDF
Scale your Magento app with Elastic Beanstalk
PPTX
Bower - A package manager for the web
PPTX
Ryan Duff 2015 WordCamp US HTTP API
PDF
Automatic testing and quality assurance for WordPress plugins and themes
PDF
Using WebSockets with ColdFusion
PDF
Modern Web Application Development Workflow - EclipseCon US 2014
PDF
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
PPTX
Drupal Development Tips
Search in WordPress - how it works and howto customize it
Improving WordPress Performance: Xdebug and PHP profiling
Xdebug, KCacheGrind and Webgrind with WampServer
Gestione avanzata di WordPress con WP-CLI - WordCamp Torino 2017 - Andrea Car...
Anthony Somerset - Site Speed = Success!
Developers, Be a Bada$$ with WP-CLI
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
Grunt and Bower
WordPress Performance optimization
My Database Skills Killed the Server
Running and Scaling Magento on AWS
Single page apps with drupal 7
Scale your Magento app with Elastic Beanstalk
Bower - A package manager for the web
Ryan Duff 2015 WordCamp US HTTP API
Automatic testing and quality assurance for WordPress plugins and themes
Using WebSockets with ColdFusion
Modern Web Application Development Workflow - EclipseCon US 2014
Optimising Your Front End Workflow With Symfony, Twig, Bower and Gulp
Drupal Development Tips
Ad

Similar to Improving WordPress performance (xdebug and profiling) (20)

PDF
Optimizing WordPress for Performance - WordCamp Houston
PDF
Mastering WordPress Vol.1
PDF
Fast Websites: The What, Why, and How
PDF
23 Ways To Speed Up WordPress
PDF
The 5 most common reasons for a slow WordPress site and how to fix them
PDF
Roshan Bhattarai: Scaling WordPress for high traffic sites
PPTX
Scaling wordpress for high traffic
PDF
Caching in WordPress
PPTX
Best Practices for WordPress in Enterprise
PPTX
A crash course in scaling wordpress
PDF
WordCamp RVA 2011 - Performance & Tuning
PDF
Php go vrooom!
PDF
Screaming Fast Wpmu
PDF
WordCamp RVA
PDF
WordCamp RVA 2011 - Performance & Tuning.pdf
PDF
WordCamp RVA 2011 - Performance & Tuning.pdf
PDF
WordCamp RVA
PPT
Roy foubister (hosting high traffic sites on a tight budget)
PDF
Best practices-wordpress-enterprise
PPTX
Caching 101
Optimizing WordPress for Performance - WordCamp Houston
Mastering WordPress Vol.1
Fast Websites: The What, Why, and How
23 Ways To Speed Up WordPress
The 5 most common reasons for a slow WordPress site and how to fix them
Roshan Bhattarai: Scaling WordPress for high traffic sites
Scaling wordpress for high traffic
Caching in WordPress
Best Practices for WordPress in Enterprise
A crash course in scaling wordpress
WordCamp RVA 2011 - Performance & Tuning
Php go vrooom!
Screaming Fast Wpmu
WordCamp RVA
WordCamp RVA 2011 - Performance & Tuning.pdf
WordCamp RVA 2011 - Performance & Tuning.pdf
WordCamp RVA
Roy foubister (hosting high traffic sites on a tight budget)
Best practices-wordpress-enterprise
Caching 101
Ad

More from Otto Kekäläinen (20)

PDF
FOSDEM2021: MariaDB post-release quality assurance in Debian and Ubuntu
PDF
MariaDB quality assurance in Debian and Ubuntu
PDF
DebConf 2020: What’s New in MariaDB Server 10.5 and Galera 4?
PDF
Technical SEO for WordPress - 2019 edition
PDF
How MariaDB packaging uses Salsa-CI to ensure smooth upgrades and avoid regre...
PDF
DebConf 2019 MariaDB packaging in Debian BoF
PDF
Technical SEO for WordPress
PDF
WordPress-tietoturvan perusteet
PDF
Technical SEO for WordPress - 2017 edition
PDF
MariaDB adoption in Linux distributions and development environments
PDF
WordPress security 101 - WP Jyväskylä Meetup 21.3.2017
PDF
WordPress security 101 - WP Turku Meetup 2.2.2017
PDF
Find WordPress performance bottlenecks with XDebug PHP profiling
PDF
Testing and updating WordPress - Advanced techniques for avoiding regressions
PDF
Git best practices 2016
PDF
MariaDB Developers Meetup 2016 welcome words
PDF
MariaDB in Debian and Ubuntu: The next million users
PDF
Koodikerho PEPE Pajapäivä 6.9.2016
PDF
MariaDB Foundation presentation and membership info
PDF
DebConf16 BoF on MariaDB/MySQL packaging
FOSDEM2021: MariaDB post-release quality assurance in Debian and Ubuntu
MariaDB quality assurance in Debian and Ubuntu
DebConf 2020: What’s New in MariaDB Server 10.5 and Galera 4?
Technical SEO for WordPress - 2019 edition
How MariaDB packaging uses Salsa-CI to ensure smooth upgrades and avoid regre...
DebConf 2019 MariaDB packaging in Debian BoF
Technical SEO for WordPress
WordPress-tietoturvan perusteet
Technical SEO for WordPress - 2017 edition
MariaDB adoption in Linux distributions and development environments
WordPress security 101 - WP Jyväskylä Meetup 21.3.2017
WordPress security 101 - WP Turku Meetup 2.2.2017
Find WordPress performance bottlenecks with XDebug PHP profiling
Testing and updating WordPress - Advanced techniques for avoiding regressions
Git best practices 2016
MariaDB Developers Meetup 2016 welcome words
MariaDB in Debian and Ubuntu: The next million users
Koodikerho PEPE Pajapäivä 6.9.2016
MariaDB Foundation presentation and membership info
DebConf16 BoF on MariaDB/MySQL packaging

Recently uploaded (20)

PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
assetexplorer- product-overview - presentation
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Designing Intelligence for the Shop Floor.pdf
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Cost to Outsource Software Development in 2025
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
history of c programming in notes for students .pptx
Digital Systems & Binary Numbers (comprehensive )
Design an Analysis of Algorithms II-SECS-1021-03
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
assetexplorer- product-overview - presentation
Why Generative AI is the Future of Content, Code & Creativity?
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
How to Choose the Right IT Partner for Your Business in Malaysia
Designing Intelligence for the Shop Floor.pdf
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Reimagine Home Health with the Power of Agentic AI​
Navsoft: AI-Powered Business Solutions & Custom Software Development
Softaken Excel to vCard Converter Software.pdf
Design an Analysis of Algorithms I-SECS-1021-03
Cost to Outsource Software Development in 2025
Operating system designcfffgfgggggggvggggggggg
wealthsignaloriginal-com-DS-text-... (1).pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Wondershare Filmora 15 Crack With Activation Key [2025
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
history of c programming in notes for students .pptx

Improving WordPress performance (xdebug and profiling)

  • 1. IMPROVING WORDPRESS PERFORMANCE Xdebug and PHP profiling WordCamp Athens 2017 Otto Kekäläinen Seravo.com @ottokekalainen
  • 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. Enterprise grade hosting and upkeep for WordPress
  • 4. WORDPRESS SUCCESS FACTORS 1. Easy to use 2. Easy to extend
  • 6. A WEB FULL OF WRONG ADVICE Most of the guides and tutorials on security and speed lack evidence.
  • 7. I’ve done mythbusting at many WordCamps with WordPress Security 101 seravo.com/wordpress-security-101/
  • 8. Now it is time to make sense out of WordPress Speed Performance
  • 9. STEP 1: Measure STEP 2: Optimize STEP 3: Validate STEP 4: Rinse and repeat
  • 10. STEP 1: Measure Find out your baseline to make sure your optimizations later at least do not worsen the performance!
  • 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. HOW FAST IS WORDPRESS? = How fast PHP code generates the HTML = HTTP request time
  • 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. 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. 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. 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. ANALYZE WITH GOACCESS ➔ Average load time ➔ Cumulative load time = sum of all loads
  • 18. STEP 2: Optimize Find and solve the bottleneck
  • 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. 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. A LITTLE MORE DEPTH: DEBUG BAR
  • 22. THE PROFESSIONAL WAY: XDEBUG A tool for developers to ● analyze PHP execution ● find bottle necks ● xdebug.org
  • 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. 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. WEBGRIND INSTALLATION $ cd /data/wordpress/htdocs $ git clone https://github.com/jokkedk/webgrind $ sudo apt-get install graphviz
  • 26. PREINSTALLED IN VVV AND SERAVO VAGRANT laptop$ vagrant ssh vagrant$ xdebug_on # Varying Vagrant Vagrants vagrant$ wp-xdebug-on # Seravo Vagrant
  • 29. FILTER FOR USUAL SUSPECTS ● load ● open ● curl ● query
  • 33. FREQUENT OR LONG DB QUERIES? Fix Avada theme upgrade check
  • 35. EXTERNAL HTTP REQUESTS ON EVERY PAGE LOAD?
  • 36. DEVELOPERS: PLEASE LEARN TO USE THE WP TRANSIENT API! Most DB queries and external PHP::curl request can be cached easily:
  • 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
  • 40. STEP 4: Rinse & repeat
  • 41. DEMO: How fast can we make Twentyseventeen?
  • 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. STEP 3: VALIDATE Before: 500-600 ms After: 300-400 ms
  • 46. REMEMBER ● Nginx access logs easy ● Xdebug never in production ● xhprof/uprofiler can be production ● PCEL APD (2004) ● memory_get_usage(), microtime()