-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessor.php
executable file
·56 lines (47 loc) · 1.43 KB
/
Processor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Querylog_Processor
*
* @category Addon
* @package addon.querylog
* @author Ebine Yutaka <[email protected]>
* @copyright 2004-2008 Mori Reo <[email protected]>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
*/
class Querylog_Processor extends Sabel_Bus_Processor
{
protected $responseName = "QUERY_LOG_HTML";
public function execute(Sabel_Bus $bus)
{
$response = $bus->get("response");
if (!$queries = Sabel_Db_Statement::getExecutedQueries()) {
return $response->setResponse($this->responseName, "");
}
$rows = array();
for ($i = 0, $c = count($queries); $i < $c; $i++) {
$query = $queries[$i];
$binds = "";
if (!empty($query["binds"])) {
$buf = array();
foreach ($query["binds"] as $k => $v) {
$buf[] = "{$k} => {$v}";
}
$binds = implode(", ", $buf);
}
$rows[$i]["sql"] = $query["sql"];
$rows[$i]["binds"] = $binds;
$rows[$i]["time"] = sprintf("%.3f", $query["time"] * 1000);
if ($query["time"] > 2000) {
// Slow Query
// ...
}
}
if ((ENVIRONMENT & PRODUCTION) > 0) {
$response->setResponse($this->responseName, "");
} else {
ob_start();
include (dirname(__FILE__) . DIRECTORY_SEPARATOR . "html.tpl");
$response->setResponse($this->responseName, ob_get_clean());
}
}
}