We wanted to profile a few PHP scripts, so we tried xdebug, but there were a few issues:
- Not suitable for a production server
- Difficult to turn on/off for specific scripts and requests
- Difficult to profile MySQL queries, without also attracting a mass of other data
xdebug is better for offline application profiling.
If you just want to track down a bottleneck, or see what your script is spending all its time doing, here’s a simple alternative.
To profile your SQL, replace mysql_query with mysql_queryx.
This generates a CSV file at /tmp/profile.1 for easy analysis.
Now create the file profile.php:
Too easy!
To stop profiling a page, set $profile = false.
If you’re concerned about performance, do something like $profile = rand(0, 100) > 99.