Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling PHP code

I'd like to find a way to determine how long each function in PHP, and each file in PHP is taking to run. I've got an old legacy PHP application that I'm trying to find the "rough spots" in and so I'd like to locate which routines and pages are taking a very long time to load, objectively.

Are there any pre-made tools that allow for this, or am I stuck using microtime, and building my own profiling framework?

like image 599
Adam Ness Avatar asked Sep 25 '08 14:09

Adam Ness


People also ask

What kind of information is acquired when profiling a PHP script?

Standard PHP profiler Standard profilers periodically record stack traces of their application. These samples give you a snapshot of important metrics like CPU, memory usage, time spent per line of code, and frequency of method calls.

What is xdebug Profiler?

Xdebug's Profiler is a powerful tool that gives you the ability to analyse your PHP code and determine bottlenecks or generally see which parts of your code are slow and could use a speed boost.


1 Answers

I have actually done some optimisation work last week. XDebug is indeed the way to go.

Just enable it as an extension (for some reason it wouldn't work with ze_extension on my windows machine) , setup your php.ini with xdebug.profiler_enable_trigger=On and call your normal urls with XDEBUG_PROFILE=1 as either a get or a post variable to profile that very request. There's nothing easier!

Also, i can really reccommend webgrind , a webbased (php) google Summer Of Code project that can read and parse your debug output files!

like image 123
SchizoDuckie Avatar answered Oct 14 '22 11:10

SchizoDuckie