[wp-trac] [WordPress Trac] #14859: WP-DB Add query_done Action for Performance Logging Plugins

WordPress Trac wp-trac at lists.automattic.com
Tue Sep 14 01:13:25 UTC 2010


#14859: WP-DB Add query_done Action for Performance Logging Plugins
-------------------------+--------------------------------------------------
 Reporter:  sexytyranno  |       Owner:                 
     Type:  enhancement  |      Status:  new            
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Database     |     Version:  3.0.1          
 Severity:  normal       |    Keywords:                 
-------------------------+--------------------------------------------------

Comment(by sexytyranno):

 As a point of reference, basically how my query_done action handler that
 works well for this is written as follows:

 {{{
 // This dbh is set up on initialization, with new_link=true passed to the
 mysql_connect call.
 $PREFIX_dbh = null;

 function handle_query_done($query_data) {
         // Only log slowness that an admin user sees, to avoid logging
 gigs of records.
         if (!current_user_can('manage_options'))
                 return true;

         // NB: WE MUST AVOID INFINITE RECURSION. And so this flag exists.
         // NB(2): DO NOT USE THE GLOBAL $wpdb. Using it will corrupt the
 state and cause almost ALL functionality of the site to cease.
         global $PREFIX_in_query_done;
         if($PREFIX_in_query_done)
                 return true;
         $PREFIX_in_query_done = true;
         // YOUR CODE STARTS HERE.

         // Log it in some way. Optionally, only log it when some
 interesting condition is met (i.e., query_time > 200ms).

         // YOUR CODE SHOULD NOT EXIST BELOW HERE
         return !($PREFIX_in_query_done = false);
 }
 }}}

 Probably not the best way to do it, given I'm still new to WP plugin dev,
 but it sanely avoids the issues described above.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14859#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list