I am using a database connection shell to host arround profiling archiving. That way, I can drop the shell or change it without changing the base connector class.
class dbcon { function query( $q ) {} } class profiled_dbcon() { private $dbcon; private $thresh; function __construct( dbcon $d, $thresh=false ) { $this->dbcon = $d; $this->thresh = $thresh; } function queury( $q ) { $begin = microtime( true ); $result = this->dbcon->query(); $end = microtime( true ); if( $this->thresh && ($end - $begin) >= $this->thresh ) error_log( ... ); return $result; } }
For profiling with a threshold of 10 seconds:
$dbc = new profiled_dbcon( new dbcon(), 10 );
I use error_log (), which was. I will not register query performance on the database server, which affects the performance of the database server. You would prefer your web heads to perceive this influence.
source share