How can I use a PHP code profiler for with Symfony CLI scripts? [closed]
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this questionMy 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.
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.
webgrind works really well for me
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.
精彩评论