0

My environments include OS X with Zend Server CE and Ubuntu Server, Apache 2. Developing with Symfony 1.4 & Doctrine on PHP 5.3.

I'm searching for a profiler that can be used with command-line PHP scripts as well as Apache-invoked PHP. At the moment my need for command-line is actually more urgent than the web scripts.

I have already done some brute-force timing via logging microtime() intervals to good effect but I'd like to be able to get total times for each function being called and without so much hand-coding.

While my main concern is time profiling, a memory profiler would also be very useful. Similar to using microtime() I've occasionally had to make repeated calls to memory_get_usage() before and after instantiating large objects or collections to get an idea how big their footprint is.

ybull
  • 1,031
  • 10
  • 17
  • 1
    A discussion of various PHP profiling tools: http://stackoverflow.com/questions/21133/simplest-way-to-profile-a-php-script – Dan Blows Apr 27 '11 at 20:35

3 Answers3

4

XDebug can do profiling. Well... it can gather profiling data for you. You can then use other applications to analyze this data. Follow the link for more information.

Sander Marechal
  • 22,978
  • 13
  • 65
  • 96
3

webgrind works really well for me

Flask
  • 4,966
  • 1
  • 20
  • 39
1

Here's the final solution that I'm quite happy with.

I tried installing XDebug 2.1.1 via the command:

pecl install xdebug 

However, this was failing miserably with this kind of error:

Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. ERROR: `phpize' failed

After a bunch of searching I came across someone else who had tried this on OS X. Fortunately they mentioned that installing Apple Xcode would provide the autoconf, phpize and other needed tools.

I got Xcode 3 and installed that, then re-tried the pecl install xdebug and it worked beautifully. After learning how to enable xdebug in my CLI instance of PHP and figuring out where the output files went, I then moved on to Webgrind. Within a couple minutes of looking at my first webgrind report, I was happily pinpointing the areas of my symfony task to optimize. It has been fabulous.

Also in my searching I happened across this promising page about how to use Xdebug for MEMORY profiling. I haven't yet attempted this but wanted to add it here in case it helps anyone else.


I received one helpful comment with a link to a relevant discussion and two partial answers which were both helpful. I gave each of those responders an upvote and indicated so.

I wish S.O. didn't seem to place such emphasis on accepting a single answer, but since it does, I'm writing a more complete answer and accepting it but made sure to give all the helpful responders upvotes. Thanks again.

ybull
  • 1,031
  • 10
  • 17