0845 205 0292

Request A Free Website Analysis

Close

Profiling queries with Zend

July 20th, 2010 by

Zend is a powerful framework that offers a LOT of functionality. I’m going to take this moment to talk about using Firebug’s extension FirePHP, which will allow Zend to show you messages about what your application is doing. Now there are a lot of tutorials available which pretty much all say the same thing, which for me did not work. I’m one of those people who can be classified as a fringe case. For example, I have my database information in the /applications/configs/applications.ini file, not in the bootstrap.

[cc]
[production]
…rest of settings…
resources.db.adapter = “pdo_mysql”
resources.db.params.host = “localhost”
resources.db.params.username = “root”
resources.db.params.password = “password”
resources.db.params.dbname = “db-name”
[/cc]

This means that the tutorials won’t work for me because I can’t set $db (see the link above to find out what I’m talking about).

After a lot of head banging a colleague pointed me in the right direction and we finally got this working right:

The following function needs to be placed in the bootstrap file.

[cc]
protected function _initDebug()
{
$logger = new Zend_Log();
$writer = new Zend_Log_Writer_Firebug();
$logger->addWriter($writer);
$registry = new Zend_Registry(array(), ArrayObject::ARRAY_AS_PROPS);
Zend_Registry::setInstance($registry);
$registry->logger = $logger;
}
[/cc]

This is telling Zend to create a Logger, let it write to Firebug, and register it so that it can be used anywhere in the application. Nice and simple. Now we need to turn it on. In the applications.ini file place the following code:

[cc]
[development : production]
…rest of settings…
resources.db.params.profiler.enabled = true
resources.db.params.profiler.class= Zend_Db_Profiler_Firebug
[/cc]

If you didn’t know, the square brackets indicate the application environment. This allows you to use different settings during development than when the site is in production (live), for example you can use a different set of database details.

Finally, in FireBug, make sure that the ‘Net’ console is ‘Enabled’.

FireBug FirePHP Net Enabled

That’s it. Quick and painless. Now whenever Zend executes a query, it will output the query to FireBug / FirePHP.

You can also use FirePHP to display information, as an alternative to putting echo, print_r and dump_var into your code to debug stuff.
[cc]
Zend_Registry::get(‘logger’)->log($message, Zend_Log::INFO);
[/cc]
$message can be a string or an array, and there are three log-types available: INFO, ERR, and WARN (also called CRIT), allowing you to prioritise all logs in FirePHP and view the debugging information based on the log-type.

This entry was posted on Tuesday, July 20th, 2010 at 9:15 am . RSS GlobeYou can follow any responses to this entry through the RSS feed.

Link to us

If you want to link to this blog, copy and paste the following HTML code to your website.

Navigation

Blog Categories

Free SEO Analysis & Proposal

From The Blogread news

  • FEB 13
    I've spent a bit of time recently covering the Facebook SEC S-1 filing that has been made in preparation for their IPO, including 5 of the most significant risk factors that Facebook faces.  In this blog I'd like to focu...
  • FEB 12
    Link building is still a process integral to any search engine optimisation campaign.  While the school of thought that social media marketing is the new link building is relatively well established, there is still a pla...

Latest Newsread news

  • FEB 13
    In December Bing became the number 2 search engine in the US beating Yahoo. In January Bing continued to take more of the market share and Yahoo continued to decline. Google also continued to climb and now has a 66.2% share of the...
  • FEB 10
    A Study was recently carried out by a US not for profit Research Company called Pew Internet, the survey revealed that the majority of users who engage in social media sites on a regular occurrence have a positive experiences and ...

Clients Say...

"We've long been considering an SEO campaign and have researched the benefits that it could potentially bring to our web presence," commented 3663 Catering Equipment's Managing Director Paul Knight. "The team at Click Consult put together a very attractive package and we're pleased to be able to enter into a sound business partnership with them. We're looking forward to seeing the results they can provide for the 3663 Catering Equipment website moving forward."

3663

Managing Director - 3663 Catering

"We have been working with Click Consult for over a year now. We are delighted with the increase in unique visitors to our site and they have far exceeded our conversion KPI metrics for customer database registrations. We rank in the top 3 for all keywords that we asked Click Consult to optimize for us. This agency know how to produce results."

hills pets

Managing Director - Liverpool One

"Whilst we have a long term keyword strategy, Click Consult have a good appreciation of our business and have a flexible approach to implementing short term keyword strategies to coincide with the peaks of the retail calendar. I receive a monthly performance report from Click Consult detailing the relevant data I require but in addition, I can review the work being undertaken at any time by logging in to their bespoke reporting system."

hills pets

CRM Manager - Liverpool One

"Hills has been looking for an agency that is able to quickly deliver in the search marketing area and catapult EMEA websites ahead of the competition. Taking SEO Consult for this project turned out to be a smart choice. Not only have they managed to significantly increase search engine traffic to our websites, but they also come with innovative ideas that can be turned to reality. I can simply say they deliver. And it's always a pleasure talking to them."

hills pets

Managing Director - Hills Pets