Skip to content

Instantly share code, notes, and snippets.

@askobara
Created January 30, 2018 13:59
Show Gist options
  • Save askobara/85f6261bdbb2ac392d49125642607df9 to your computer and use it in GitHub Desktop.
Save askobara/85f6261bdbb2ac392d49125642607df9 to your computer and use it in GitHub Desktop.
Yii2 loggin db profiling
'response' => [
'on afterSend' => function ($event) {
list($queryCount, $totalExecTime) = Yii::getLogger()->getDbProfiling();
list($mongoQueryCount, $mongoTotalExecutionTime) = mongodb_profiling();
$elapsedTime = Yii::getLogger()->getElapsedTime();
$request = Yii::$app->getRequest();
Yii::info(\yii\helpers\VarDumper::dumpAsString([
'url' => "{$request->getMethod()} {$request->getAbsoluteUrl()}",
'body' => $request->getBodyParams(),
'db_query_count' => $queryCount,
'db_total_execution_time' => $totalExecTime,
'mongodb_query_count' => $mongoQueryCount,
'mongodb_total_execution_time' => $mongoTotalExecutionTime,
'elapsed_time' => $elapsedTime,
]), 'perf');
}
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment