- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
class MyEvents extends \Event\EventsHandler {
static $key = 1;
public function BeforeQuery() {
Timer::start(self::$key);
}
public function AfterQuery() {
Timer::step(self::$key++);
if(Timer::$last['different'] > 1) {
$debug_backtrace = debug_backtrace();
foreach($debug_backtrace as $k=>$v) {
if($v['function'] == 'q') {
$error = "QUERY: ".$v['args'][0]."\n".
"file: ".$v['file']."\n".
"line: ".$v['line']."\n".
"date: ".date("Y-m-d H:i:s")."\n".
"===================================";
file_put_contents('./logs/slowquery.log',$error."\r\n",FILE_APPEND);
break;
}
}
}
}
public function ShutDownSystem() {
echo microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
}
}
Event::setEventHandler('MyEvents');
q("SELECT * FROM `table` ORDER BY RAND()");
q("SELECT NOW()");
echo Timer::result();