We have been working on a few projects using Doctrine 2 and Zend Framework (ZF). We are using the Bisna Package (some additional documentation available here) as the glue to get everything working together nicely.
When working with any application it is always useful to have some kind of reporting mechanism for execution time, number of queries, memory use etc and we have used the following to help us profile our applications.
Doctrine 2 provides a simple interface for logging, namely
and the following resources implement it.
- ZFDebug Doctrine 2 plugin by Sandy Pleyte and improved with python-sqlparse support by Stephen Fuhry. There is currently a pull request for integration of the Doctrine2 plugin into the main ZFDebug project, until then you can get it from Stephen’s company’s repository https://github.com/MontmereLimited/ZFDebug
- FirePHP implementation of the SQLLogger and the Zend Wildfire FirePHP plugin from Micheal Ridgway available at https://github.com/mridgway/ZendX_Doctrine2/
Using ZFDebug and the Doctrine 2 plugin
Download and unpack the ZFDebug package from https://github.com/MontmereLimited/ZFDebug
Drop the ZFDebug folder found in the ‘library’ directory of the unzipped package next to your Zend folder in the library directory of your application.
The ZFDebug plugin includes the following code for bootstrapping the ZFDebug bar with Doctrine 2
As our Doctrine 2 configuration is set in the application.ini we are using the following code
You can also install and enable the python-sqlparse on your development environment to prettify the SQL output, however this will increase your script execution time for each application, I noticed an increase of ~1 second locally.
Using FirePHP to profile Doctrine 2
Then download https://github.com/mridgway/ZendX_Doctrine2/ and extract the above package from github.
Grab the ZendX directory found inside lib in the package, and drop it into your application’s library directory (next to your Zend folder as with ZFDebug).
You can then load the plugin with the following code
Then load up your app in firefox and check out the console in Firebug for query logging goodness.
N.B. There appears to be a FirePHP extension for Chrome, but I couldn’t get it working, so I would recommend using ZFDebug if Chrome is your browser of choice.
There is also a plugin for Doctrine 1 and ZFDebug
- Eric Leclerc’s Doctrine 1 ZFDebug plugin https://github.com/danceric/zfdebugdoctrine