Last active
September 4, 2023 13:33
-
-
Save azizramdan/4d6f8b2ac5180eec70555f74ddcab401 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function getSql($query) | |
{ | |
$bindings = $query->getBindings(); | |
return preg_replace_callback('/\?/', function ($match) use (&$bindings, $query) { | |
return $query->getConnection()->getPdo()->quote(array_shift($bindings)); | |
}, $query->toSql()); | |
} | |
use Illuminate\Database\Events\QueryExecuted; | |
use Illuminate\Support\Facades\Event; | |
use Illuminate\Support\Facades\Log; | |
Event::listen(QueryExecuted, function (QueryExecuted $event) { | |
if ($event->time > 1000) { | |
Log::info('Slow query detected.', [ | |
// ... | |
]); | |
} | |
}); | |
use Illuminate\Database\Connection; | |
use Illuminate\Support\Facades\DB; | |
DB::whenQueryingForLongerThan(1000, function (Connection $connection) { | |
Log::info('Queries collectively took longer than 1 second.', [ | |
// ... | |
]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment