Skip to content

Instantly share code, notes, and snippets.

@tqmz
Created July 27, 2012 06:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tqmz/3186534 to your computer and use it in GitHub Desktop.
Save tqmz/3186534 to your computer and use it in GitHub Desktop.
Xhprof: profiling PHP applications

Xhprof (PHP Profiling)

Reference: Setup + Usage

Tips: Setup

  • pecl installation did work with PHP 5.3.8 (but not with 5.3.6)
  • make sure webserver can read the profiles (path + files)
  • use web client and profile generator of same version (symlink)

Tips: Embedding

  • use composer to load xhprof vendor
  • wrap Xhprofile class
  • use configurable base profile for iterative tuning
  • log URLs with single and compare mode

Tips: Interpreting the results

  • assure conditions remain constant (calling params, system load, network ...)
  • spread resources usage, know your bottlenecks

Example: XML import script

http://127.0.0.1/xhprof_html/?run=50115a12c6086&source=cm_see__uab&sort=excl_wt

  • optimize database configuration (mysql tuning primer, driver and query)
  • use DataMapper instead of dynamic getters, cache as soon all static data are set
  • improve date filters, e. g. based on indices
  • use xpath queries for smaller SimpleXmlElements, try to reduce XmlReader reads
  • cut off XML that is not needed file base # sed
  • replace generalized / defensive framework methods / add riskier ones
  • exclude data as soon as possible: try to find and avoid invalid objects in advance

Further Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment