Query Profiling with Zend Framework and FirePHP
at 8.47amMy last post was about logging with Zend Framework and FirePHP. This one is similar but, for me at least, just as useful. The Zend Framework can use the WildFire protocol (that allows client-server communication through HTTP headers) to allow the PHP database adapter to report directly to FirePHP about every query that goes through it. Along with a record of the query is the time the query took to execute. This allows you to see where the bottlenecks are in your SQL or simply whether you are running too many queries.
The set-up for this is even easier than before. Again, if you are using Zend_Controller_Front then this needs to be executed before you dispatch, otherwise before you send headers. The variable $db mentioned should be an instance of Zend_Db_Adapter_Abstract.
$profiler = new Zend_Db_Profiler_Firebug('SQL Queries'); $profiler->setEnabled(true); $db->setProfiler($profiler);
As in the last example I normally wrap this in a conditional statement that detects whether profiling is turned on in the config file. This allows for the output to be disabled at the change of a paramter.
if($config->profiling->db == 'true') { $profiler = new Zend_Db_Profiler_Firebug('SQL Queries'); $profiler->setEnabled(true); $db->setProfiler($profiler); }
More information can be found in the relevant section of the Zend Framework Reference Guide.