The Unknown
The Unknown

Reputation: 19704

PHP Profiler for a live system on top of Apache

I have a PHP website on a Apache server, and I would like to know if there are tools and other ways I can profile this to find bottlenecks on the code. What I need to know is what functions are taking long to process, etc.

Something like gprof, except for PHP on live apache server.

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

Upvotes: 6

Views: 6552

Answers (9)

Your Common Sense
Your Common Sense

Reputation: 157839

Let me also mention Pinba
In my opinion, it is more suitable for the multiple servers setup rather than for just one server, but in case your project grow..

Upvotes: 1

kannan
kannan

Reputation: 31

XHProf was designed for this use case.

XHProf (open sourced by Facebook in 2009) powers Facebook's XHProfLive -- a real-time performance monitoring system that provides function level insights from production tiers.

A snippet from XHProf doc:

XHProf is a light-weight instrumentation based profiler. During the data collection phase, it keeps track of call counts and inclusive metrics for arcs in the dynamic callgraph of a program. It computes exclusive metrics in the reporting/post processing phase. XHProf handles recursive functions by detecting cycles in the callgraph at data collection time itself and avoiding the cycles by giving unique depth qualified names for the recursive invocations.

XHProf's light-weight nature and aggregation capabilities make it well suited for collecting "function-level" performance statistics from production environments.

regards, Kannan Muthukkaruppan

Upvotes: 3

edik
edik

Reputation: 11

dtrace has low overhead

dtrace in fact has almost zero overhead unless you enable thousands of probes think it is also available on the BSD's

Upvotes: 1

CruiZen
CruiZen

Reputation: 182

If you are running on OpenSolaris, consider dtrace. The biggest advantage probably is that you can also probe into other layers like Apache, Mysql. dtrace has low overhead and you can selectively enable only the probes that you want to monitor.

Upvotes: 0

Martijn Heemels
Martijn Heemels

Reputation: 3659

I would suggest against building your own profiler. There are several excellent profilers freely available that will give you extensive detail and ease of use. I think your best time investment is in the following combination. We use this at the web developent company I work for, and are very pleased with it:

  1. The Zend Server php stack:
    You can use the free Community Edition, and choose which parts of the stack you want to install. We installed only the PHP part, and rely on the Apache and MySQL from the Linux distro. Zend Server provides a Debugger extension, a code optimizer (for a slight speed boost), a bytecode cache (for a substantial speed boost) and a nice GUI for managing PHP settings. The commercial version provides much more. Installation in Linux is easy via RPM or DEB packages.

  2. To use the Debugger extension you need an IDE:
    Install Zend Studio which is an excellent PHP IDE (check the features page), and makes debugging and profiling very easy. No need to make cachegrind files, or other multistep processes, but just click Profile in the toolbar in Firefox and Studio starts profiling that page. The detail and ease of use are huge.

Maybe I'm sounding like a Zend salesman, and maybe this sounds like more than you need, but I'm just a PHP developer who is very happy with the tools he uses. I think it's time well spent to start using Studio, but the combination makes it great and Server will even speed up your live server quite a bit. In my opinion this combo is simply the best PHP development environment currently available. Check out the demo videos. There's one on profiling too.

Upvotes: 0

KM.
KM.

Reputation: 103587

if you have a very targeted area to look at, you may want to try sprinkling these 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);

Upvotes: 1

Paul Dixon
Paul Dixon

Reputation: 300825

You can use xdebug - once installed you can trigger profiling of requests in a variety of ways, and you wind up with a valgrind format profile for each request. Load this in WinCacheGrind, KCacheGrind or similar and drill down to find where all the time is spent!

alt text

Upvotes: 8

pagid
pagid

Reputation: 13867

Try XDebug ( http://www.xdebug.org/ ) you can trigger it with a get-parameter during your debugging-session. This will create cachegrind-files which you can check within KCacheGrind or WinCacheGrind (this first is much better)...

Upvotes: 4

f00860
f00860

Reputation: 3576

You can use phpdebug for this job. It's a php extension.

Upvotes: 0

Related Questions