PHP + MySQL profiler

Do you know how vBulletin has a sql profiler in debug mode? How can I build one for my own web application? It is built in procedural PHP.

Thanks.

+4
source share
3 answers

http://dev.mysql.com/tech-resources/articles/using-new-query-profiler.html

The above link links how you can get sql profile information after any request.

The best way to implement this is to create a database class and have a "profile" flag to enable query logging and related information, as shown above, in the link above.

Example:

Class dbthing{ var $profile = false; function __construct($profile = false){ if($profile){ $this->query('set profiling=1'); $this->profile = true; } ... } function query($sql, $profile_this == false){ ... if($this->profile && !$profile_this) $this->query("select sum(duration) as qtime from information_schema.profiling where query_id=1", true); ... // store the timing here } } 
+7
source

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.

+3
source

Late, Open PHP MyProfiler will help you achieve this, and you can extract the functional sections from the code for your use.

0
source

All Articles