PHP+;MySQL档案器

PHP+;MySQL档案器,mysql,profiling,Mysql,Profiling,您知道vBulletin在调试模式下如何使用sql探查器吗?我如何为自己的web应用程序构建一个呢?它内置于过程PHP中 谢谢 上面的链接链接了如何在任何查询之后获取所有sql概要文件信息 实现它的最佳方法是创建一个数据库类,并使其具有一个“profile”标志,以打开查询日志和适当的信息,如上面的链接所示 例如: Class dbthing{ var $profile = false; function __construct($profile = false){ if($

您知道vBulletin在调试模式下如何使用sql探查器吗?我如何为自己的web应用程序构建一个呢?它内置于过程PHP中

谢谢

上面的链接链接了如何在任何查询之后获取所有sql概要文件信息

实现它的最佳方法是创建一个数据库类,并使其具有一个“profile”标志,以打开查询日志和适当的信息,如上面的链接所示

例如:

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
  }

}

我使用一个数据库连接包装器,我可以在周围放置一个分析包装器。通过这种方式,我可以丢弃或更改包装器,而无需更改我的基本连接器类

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;  
    }
}
对于具有10秒阈值的评测:

$dbc = new profiled_dbcon( new dbcon(), 10 );

我让它使用error_log()记录时间。我不会将查询性能记录回数据库服务器,这会影响数据库服务器的性能。你宁愿让你的网络主管来承担这种影响。

虽然很晚,但会帮助你实现这一点,你可以从代码中提取功能部分供你使用。

这不会给出准确的结果,因为microtime()提供的是服务器时间,而不是操作所需的实际处理器时间(或高清访问时间等)最好使用mysql内置函数来获取进程的长度took@mikev:说得很好。感谢您发布关于mysql profiler功能的链接,我很高兴了解更多。您不是在为自己创建工作吗?为什么不使用mysql慢速查询日志呢?如果您是针对库存mysql 5.0系统开发的,而您不是如果您没有向数据库中添加次秒慢速查询日志补丁的选项,那么这将成为您的下一个选项。