4
A
回答
7
http://dev.mysql.com/tech-resources/articles/using-new-query-profiler.html
上面的鏈接鏈接,您如何能得到任何人查詢後的SQL配置文件信息。
實現它的最佳方法是創建一個數據庫類並讓它有一個「配置文件」標誌來打開查詢記錄和相應的信息,如上面鏈接所示。
實施例:
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
}
}
3
我使用數據庫連接的包裝,我可以角落找尋放置一個分析包裝。這樣我可以丟棄包裝器,或者更改它,而無需更改我的基礎連接器類。
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中()什麼時間是。我不會將查詢性能記錄回數據庫服務器,這會影響數據庫服務器的性能。你寧願讓你的網站負責人吸收這種影響。
0
雖然很晚,但Open PHP MyProfiler可以幫助您實現這一目標,並且您可以從代碼中提取功能部分以供您使用。
相關問題
- 1. MySQL查詢分析器
- 2. MySQL查詢分析器
- 3. 笑臉分析器與PHP
- 4. 分析器的Json PHP
- 5. 分析器與結構(PHP)
- 6. Soundcloud PHP ubb分析器
- 7. PHP Imap語法分析器
- 8. 分析和優化PHP/MySQL網站
- 9. 在php或MYSQL中分析數據?
- 10. Php Mysql多重分析功能
- 11. PHP/MySQL - 分析多套公共集合
- 12. Erlang分析器/分析器?
- 13. 解析器和詞法分析器生成器php
- 14. 全局打開mysql分析器
- 15. 分析PHP
- 16. 解析表(mysql,php)
- 17. SQL 2005分析器分析
- 18. 分析查詢mysql
- 19. 分析mysql數據
- 20. ocaml分析器和詞法分析器
- 21. 交叉分析報表 - MYSQL
- 22. PHP的magpierss分析器錯誤
- 23. PHP簡單的CSS串分析器
- 24. PHP - 自定義查詢分析器
- 25. php分析器xml帶捲曲
- 26. PHP雙引號串分析器
- 27. PHP簡單的HTML DOM分析器模
- 28. PHP/Codeigniter的Printf語法分析器?
- 29. 需要xhprof php分析器的文檔
- 30. PHP分析器,輸出到HTML文件
這不會給出一個準確的結果,因爲microtime()提供服務器時間而不是實際的操作所需的處理器時間(或HD訪問時間等),因此最好使用內置的函數得到一個過程需要多長時間 – 2009-10-30 22:53:02
@mike v:非常好的一點。感謝您發佈關於mysql profiler功能的鏈接,我很樂意詳細瞭解這一點。 – 2009-11-01 19:33:51
你不是在爲自己創造工作嗎?爲什麼不使用mysql慢速查詢日誌? – starmonkey 2010-10-15 00:45:54