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.
PHP Aberdeen
Quick optimisation
of PHP with
Webgrind
Andy Gaskell - @AndyGasman / @SSOFB
Webgrind
“Webgrind is a Xdebug profiling web frontend in PHP.
It implements a subset of the features of kcachegrind
and in...
Introduction
Webgrind - why?
● Characterise to optimise
● No point in optimising code without characterising
● Look inside...
Install xdebug
You probably don’t need to.
php 5
sudo apt-get install php5-xdebug
php 7
sudo apt-get install php-xdebug
...and maybe graphviz too
Just for the graphs really
sudo apt-get install graphviz
Enable xdebug everywhere
php 5
/etc/php5/apache2/php.ini
php 7
/etc/php/7.0/apache2/php.ini
Enable xdebug per thing
Pop it in your .ini or .htaccess like...
xdebug.profiler_enable=1
...great for a quick debug/profi...
Just copy the files to
Easiest bit :)
● Download from github
● Put them in a folder under your web root
● Change the confi...
Use cases?
● How can I make this bat-shit fast?
● Why is this server / system slower than the other one?
● What’s holding ...
Just hit it up in your browser
Just go to wherever you put the files, ie
http://localhost/webgrind or
http://dev.stuff.com...
Looking at results
Loads of info, have a tinker…
● Tweak the settings, to remove some noise
● Change the sorts
● Browse th...
Practical example
● API experiences large slow-down with growth in data
size
● Characterised with Webgrind
Before...
Average time:
0.442942536816s
Slowest time:
13.3827910423s
After...
Average time:
0.335654691152s
Slowest time:
...
Tricks and tips - running
● Sometimes it can take a couple of minutes to generate
the report
● Sometimes it can crash your...
Tricks and tips - analysing
● Call graphs are colour coded
● If you don’t like svg call graphs, you can set
“graphImageTyp...
Other options
● Do it in your IDE, via xdebug remote profiler
○ PHP Storm
○ Eclipse
○ NotePad++
● Use KCachegrind / Callgr...
Read more
● Webgrind website (just github)
https://github.com/jokkedk/webgrind
● Google your platform for WAMP, MAMP or NG...
Any questions?
Andy Gaskell - @AndyGasman / @SSOFB
Thanks :)
Andy Gaskell - @AndyGasman / @SSOFB
PHP Aberdeen Quick optimisation of PHP with Webgrind
PHP Aberdeen Quick optimisation of PHP with Webgrind
PHP Aberdeen Quick optimisation of PHP with Webgrind
PHP Aberdeen Quick optimisation of PHP with Webgrind
Upcoming SlideShare
Loading in …5
×

PHP Aberdeen Quick optimisation of PHP with Webgrind

162 views

Published on

Slides from a lightning talk presented at Aberdeen PHP User Group on Wednesday 3rd of August 2016.

Published in: Internet
  • Be the first to comment

  • Be the first to like this

PHP Aberdeen Quick optimisation of PHP with Webgrind

  1. 1. PHP Aberdeen Quick optimisation of PHP with Webgrind Andy Gaskell - @AndyGasman / @SSOFB
  2. 2. Webgrind “Webgrind is a Xdebug profiling web frontend in PHP. It implements a subset of the features of kcachegrind and installs in seconds and works on all platforms. For quick'n'dirty optimizations it does the job.” https://github.com/jokkedk/webgrind
  3. 3. Introduction Webgrind - why? ● Characterise to optimise ● No point in optimising code without characterising ● Look inside libraries ● Find the slow bits ● Understand the platforms you work on
  4. 4. Install xdebug You probably don’t need to. php 5 sudo apt-get install php5-xdebug php 7 sudo apt-get install php-xdebug
  5. 5. ...and maybe graphviz too Just for the graphs really sudo apt-get install graphviz
  6. 6. Enable xdebug everywhere php 5 /etc/php5/apache2/php.ini php 7 /etc/php/7.0/apache2/php.ini
  7. 7. Enable xdebug per thing Pop it in your .ini or .htaccess like... xdebug.profiler_enable=1 ...great for a quick debug/profile of system characterisation.
  8. 8. Just copy the files to Easiest bit :) ● Download from github ● Put them in a folder under your web root ● Change the config.php if the xdebug isn’t outputting to /tmp
  9. 9. Use cases? ● How can I make this bat-shit fast? ● Why is this server / system slower than the other one? ● What’s holding this up? ● How does the performance differ between library X and Y?
  10. 10. Just hit it up in your browser Just go to wherever you put the files, ie http://localhost/webgrind or http://dev.stuff.com/webgrind
  11. 11. Looking at results Loads of info, have a tinker… ● Tweak the settings, to remove some noise ● Change the sorts ● Browse the call graph ● Compare costs
  12. 12. Practical example ● API experiences large slow-down with growth in data size ● Characterised with Webgrind
  13. 13. Before... Average time: 0.442942536816s Slowest time: 13.3827910423s After... Average time: 0.335654691152s Slowest time: 0.815340042114s
  14. 14. Tricks and tips - running ● Sometimes it can take a couple of minutes to generate the report ● Sometimes it can crash your system if it’s doing big stuff ● You can see the files being created to gauge size / complexity, ie “ls -lha /tmp/cachegrind*” ● If it’s taking crazy-long, set the “show” value lower
  15. 15. Tricks and tips - analysing ● Call graphs are colour coded ● If you don’t like svg call graphs, you can set “graphImageType” to “png” in webgrind/config.php
  16. 16. Other options ● Do it in your IDE, via xdebug remote profiler ○ PHP Storm ○ Eclipse ○ NotePad++ ● Use KCachegrind / Callgrind, a Linux (KDE) profiling App
  17. 17. Read more ● Webgrind website (just github) https://github.com/jokkedk/webgrind ● Google your platform for WAMP, MAMP or NGINX info
  18. 18. Any questions? Andy Gaskell - @AndyGasman / @SSOFB
  19. 19. Thanks :) Andy Gaskell - @AndyGasman / @SSOFB

×