Find WordPress performance bottlenecks with XDebug PHP profiling

15
@ottokekalainen @Seravocom SERAVO.COM Photo by Nicola Sapiens De Mitri Optimizing WordPress performance with XDebug and PHP profiling

Transcript of Find WordPress performance bottlenecks with XDebug PHP profiling

Page 2: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

XDebug

a tool for developers toanalyze PHP execution to find bottle necks and anomalies

Page 3: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

Xdebug installation example:$ sudo apt-get install php-xdebug$ nano /etc/php/fpm/conf.d/20-xdebug.ini

; Enable xdebugzend_extension=xdebug.so

; Enable php profiling with get param XDEBUG_PROFILE=1xdebug.profiler_output_dir=/tmpxdebug.profiler_output_name=cachegrind.out.%t.%pxdebug.profiler_enable_trigger=1

$ sudo service restart php-fpm

Do this in your development environment, e.g. Vagrant image.

Don't use production site, XDebug makes the site much slower!

Page 4: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

Profiling run of WordPress front page/tmp $ curl -I http://example.com/?XDEBUG_PROFILE=1/tmp $ ll -h11M cachegrind.out.1455198789.5601/tmp $ head cachegrind.out.1455198789.5601 version: 1creator: xdebug 2.2.3cmd: /data/wordpress/htdocs/index.phppart: 1positions: lineevents: Timefl=php:internal...

Page 5: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

Webgrind installation example:$ cd /data/wordpress/htdocs$ git clone https://github.com/alpha0010/webgrind $ sudo apt-get install graphviz

Page 6: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

Go profiling!

Page 7: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

Page 8: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

Page 9: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

Filter for usual suspects: load, open, curl, query

Page 10: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

Pinpoint the bottle neck

Page 11: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

Show call graph

Page 12: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

Hunt down that rare beast:$ export LANG=C; for i in {1..99}; do curl -IL -H "Pragma: no-cache" -w "%{time_total}\n" -o /dev/null -s "http://wp-esittely.wp-palvelu.fi/?XDEBUG_PROFILE=1"; done$ ll -Sh /tmp-rw-r--r-- 111M helmi 11 16:29 cachegrind.out.1455200976.5601-rw-r--r-- 91M helmi 11 16:29 cachegrind.out.1455200984.5601-rw-r--r-- 89M helmi 11 16:29 cachegrind.out.1455200972.5604-rw-r--r-- 89M helmi 11 16:29 cachegrind.out.1455200964.5604-rw-r--r-- 88M helmi 11 16:29 cachegrind.out.1455200973.5604-rw-r--r-- 87M helmi 11 16:29 cachegrind.out.1455200963.5601-rw-r--r-- 87M helmi 11 16:29 cachegrind.out.1455200967.5601

Page 13: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

Rinse and repeat!

Page 14: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

Now go and fix your slow code!

Page 15: Find WordPress performance bottlenecks with XDebug PHP profiling

@ottokekalainen @Seravocom SERAVO.COM

PREMIUM HOSTING AND PROFESSIONAL UPKEEPFOR WORDPRESS

Thank You!