Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7599645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:42:47+00:00 2026-05-30T22:42:47+00:00

Is there a simple way to log to queries to a file? I have

  • 0

Is there a simple way to log to queries to a file? I have Firebug profiling working no problem with:

resources.db.params.profiler.enabled = "true"
resources.db.params.profiler.class = "Zend_Db_Profiler_Firebug"

It would be nice to log this to a file with out writing a bunch of code.

Is there a class I can swap out with Zend_Db_Profiler_Firebug?

UPDATE: See my answer below.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:42:48+00:00Added an answer on May 30, 2026 at 10:42 pm

    As of ZF 1.11.11 there is no built in profiler class that will log queries to a file. Currently, FireBug is the only specialized Db Profiler.

    Here are two ways in which you can solve it without loads of extra code though.

    First, check out this answer as it shows how to extend Zend_Db_Profiler to have it log the queries to a file on queryEnd. If it doesn’t quite do what you want, you can extend Zend_Db_Profiler and use the provided code as a starting point.

    This next example is a slight modification of a plugin I have in some of my applications that I use to profile queries when the application is in development. This method utilizes a dispatchLoopShutdown() plugin to get an instance of the Db Profiler and log the queries to a file.

    <?php   /* library/My/Page/DbLogger.php */
    class My_Page_DbLogger extends Zend_Controller_Plugin_Abstract
    {
       public function dispatchLoopShutdown()
       {
           $db        = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('db');
           $profiler  = $db->getProfiler();
    
           if ($profiler === NULL || !($profiler instanceof Zend_Db_Profiler))
               return;
    
           // either create your logger here based on config in application.ini
           // or create it elsewhere and store it in the registry
           $logger = Zend_Registry::get('dblog');
    
           $totalQueries = $profiler->getTotalNumQueries();
           $queryTime    = $profiler->getTotalElapsedSecs();
    
           $longestTime  = 0;
           $queries      = $profiler->getQueryProfiles();
    
           if ($queries !== false) {
               $content = "\nExecuted $totalQueries database queries in $queryTime seconds<br />\n";
    
               foreach ($queries as $query) {
                   // TODO: You could use custom logic here to log only selected queries
    
                   $content .= "Query (" . $query->getElapsedSecs() . "s): " . $query->getQuery() . "\n";
                   if ($query->getElapsedSecs() > $longestTime) {
                       $longestTime  = $query->getElapsedSecs();
                   }
               }
    
               $content .= "Longest query time: $longestTime.\n" . str_repeat('-', 80);
    
               $logger->info($content);
           }
       }
    }
    

    To activate this plugin, you can use code like this in your bootstrap:

    /**
     * Register the profiler if we are running in a non-production mode
     */
    protected function _initPageProfiler()
    {
        if (APPLICATION_ENV == 'development') {
            $front = Zend_Controller_Front::getInstance();
            $front->registerPlugin(new My_Page_DbLogger());
        }
    }
    

    Ideally, in the long term, you would probably want to make a class that extends Zend_Db_Profiler and allow additional options to be specified in your config such as the log file path, the log priority. This way you can leverage the existing filters to Zend_Db_Profiler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my log file working, but I get extraneous info on each line
Is there a simple way to log everything that appears on the command line
In Django, is there a reasonably simple way to log what templates were used
Is there any simple way to parse Ansi colors in log files, and use
Is there a simple way to have a code library automatically detect if it's
Is there a simple way to do async in Perl? I have the following
Is there a simple way to get a diff on the working directory using
Is there a simple way to trace or write some log in a ASP.Net
Is there a simple way with hibernate log level to see when the first
Is there a simple way to insert the current time (like TIME: [2012-07-02 Mon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.