PHP profiler for a live system on top of Apache

I have a PHP site on an Apache server, and I would like to know if there are tools and other ways that I can work this out to find bottlenecks in the code. I need to know which functions take a lot of time, etc.

Something like gprof other than PHP on the live apache server.

What are other ways to find bottlenecks in a PHP system.

+6
profiling php
source share
9 answers

You can use xdebug - after installation, you can invoke query profiling in various ways, and you complete the valgrind profile profile for each request. Download it to WinCacheGrind , KCacheGrind or similar, and turn around to find where all the time is spent!

alt text

+8
source share

Try XDebug ( http://www.xdebug.org/ ), you can run it with the get parameter during a debugging session. This will create cachegrind files that you can check inside KCacheGrind or WinCacheGrind (this first is much better) ...

+4
source share

XHProf was designed for this use case.

XHProf (open sourced by Facebook in 2009) supports Facebook XHProfLive is a real-time performance monitoring system that provides a representation of the level of performance from production tiers.

Excerpt from the XHProf document:

XHProf is a lightweight based profiler. During the data collection phase, it keeps track of the number of calls and inclusive metrics for arcs in the dynamic callgraph program. It calculates exceptional metrics during the reporting / post-processing phase. XHProf handles recursive functions by detecting loops in a callgrraph at the time of data collection and avoiding loops by providing unique deep qualified names for recursive calls.

XHProf light weight and aggregation capabilities make it well suited for collecting "functional level" statistics on production efficiency of media.

Regards, Kannan Mutukarapupan

+3
source share

If you have a very targeted viewing area, you can try sprinkling them around your code:

$f_timeStart=microtime(true); $f_timeLast=$f_timeStart; error_log(sprintf("%'08.5f",(microtime(true)-$f_timeLast)).' - '.sprintf("%'05.2f",(microtime(true)-$f_timeStart)).' secs - '.'01 before xyz()'."\n", 3, '/var/tmp/my-errors.log'); $f_timeLast=microtime(true); xyz(); error_log(sprintf("%'08.5f",(microtime(true)-$f_timeLast)).' - '.sprintf("%'05.2f",(microtime(true)-$f_timeStart)).' secs - '.'01 after xyz()'."\n", 3, '/var/tmp/my-errors.log'); $f_timeLast=microtime(true); 
+1
source share

dtrace has little overhead

dtrace actually has almost zero overhead, unless you include thousands of probes think it is also available on BSD

+1
source share

Let me also mention Pinba
In my opinion, it is more suitable for setting up several servers, not just for one server, but in case your project grows.

+1
source share

You can use phpdebug for this job. This is a php extension.

0
source share

I would suggest creating your own profiler. There are several excellent profilers that provide you with extensive information and ease of use. I think your best investment in the future is as follows. We use this in the web company I work for, and she likes it very much:

  • Zend Server php stack:
    You can use the free version of Community Edition and choose which parts of the stack you want to install. We have installed only part of PHP and rely on Apache and MySQL from the Linux distribution. Zend Server provides a Debugger extension, a code optimizer (for a slight increase in speed), a cache byte (for a significant increase in speed) and a beautiful graphical interface for managing PHP settings. The commercial version provides much more. Installing on Linux is easy via RPM or DEB packages.

  • To use the Debugger extension, you need an IDE:
    Install Zend Studio , which is a great PHP IDE (check out the feature page) and is very easy to debug and profile. You don’t need to make cachegrind files or other multi-stage processes, but just click the β€œProfile” button on the toolbar in Firefox and Studio to start profiling this page. The details and ease of use are enormous.

I may look like a Zend seller, and it may sound more than what you need, but I am just a PHP developer who is very pleased with the tools that he uses. I think the time taken to start using Studio, but the combination makes it great, and Server will even speed up your live server a bit. In my opinion, this combo is simply the best PHP development environment currently available. Watch demo videos . There, too, on the profiling.

0
source share

If you are using OpenSolaris, consider dtrace. The biggest advantage is probably that you can also explore other layers, such as Apache, Mysql. dtrace has low overhead, and you can selectively include only the probes you want to monitor.

0
source share

All Articles