Take the 2-minute tour ×

I'd like to find a way to determine how long each function in PHP, and each file in PHP is taking to run. I've got an old legacy PHP application that I'm trying to find the "rough spots" in and so I'd like to locate which routines and pages are taking a very long time to load, objectively.

Are there any pre-made tools that allow for this, or am I stuck using microtime, and building my own profiling framework?

share|improve this question
possible duplicate of Simplest way to profile a PHP script –  user212218 Mar 21 '12 at 16:10

9 Answers 9

up vote 38 down vote accepted

I have actually done some optimisation work last week. XDebug is indeed the way to go.

Just enable it as an extension (for some reason it wouldn't work with ze_extension on my windows machine) , setup your php.ini with xdebug.profiler_enable_trigger=On and call your normal urls with XDEBUG_PROFILE=1 as either a get or a post variable to profile that very request. There's nothing easier!

Also, i can really reccommend webgrind , a webbased (php) google Summer Of Code project that can read and parse your debug output files!

share|improve this answer
Alternative to webgrind on Windows machines: Wincachegrind (a desktop app). –  Halil Özgür Aug 18 '11 at 7:11

Here is a nice tip.

When you use XDebug to profile your PHP, set up the profiler_trigger and use this in a bookmarklet to trigger the XDebug profiler ;)

share|improve this answer

take a look into xdebug, which allows in-depth profiling. And here's an explanation of how to use xdebug.

Xdebug's Profiler is a powerful tool that gives you the ability to analyze your PHP code and determine bottlenecks or generally see which parts of your code are slow and could use a speed boost. The profiler in Xdebug 2 outputs profiling information in the form of a cachegrind compatible file.

Kudos to SchizoDuckie for mentioning Webgrind. This is the first I've heard of it. Very useful (+1).

Otherwise, you can use kcachegrind on linux or its lesser derivative wincachegrind. Both of those apps will read xdebug's profiler output files and summarize them for your viewing pleasure.

share|improve this answer

I once saw a screen-cast for Zend Core. Looks pretty good, but it actually costs money, I don't know if that's an issue for you.

share|improve this answer

XDebug is nice but its not that easy to use or setup IMO.

The profiler built into Zend Studio is very easy to use. You just hit a button on a browser toolbar and BAM you have your code profile. ts perhaps not as indepth as a CacheGrind dump, but its always been good enough for me.

You do need to setup Zend Platform too, but thats straightforward and free for development use - you'd still have to pay for the Zend Studio licence though.

share|improve this answer
Three and a half years on, I'd disagree with myself now. Facebook have open-sourced a profiling tool called XHProf which is really nice and lightweight and plenty easy enough to setup and get running –  Marc Gear Feb 28 '12 at 15:48

xdebug's profiling functions are pretty good. If you get it to save the output in valgrind-format, you can then use something like KCachegrind or Wincachegrind to view the call-graph and, if you're a visual kind of person, work out more easily what's happening.

share|improve this answer

In addition to having seriously powerful real-time debugging capabilities, PhpED from NuSphere (www.nusphere.com) has a built-in profiler that can be run with a single click from inside the IDE.

share|improve this answer

If you install the xdebug extension you can set it up to export run profiles, that you can read in WinCacheGrind (on Windows). I can't recall the name of the app that reads the files on Linux.

share|improve this answer

The easiest solution is to use Zend Profiler, you don't need Zend Platform to use is, you can run it directly from your browser, it's quite accurate and has the most features you need and it's integrated in the Zend Studio

share|improve this answer

Your Answer


