You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php
namespace App\Providers;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
//
}
public function boot(): void
{
if ($this->app->isLocal()) {
Log::debug('Starting DB Logging...');
DB::listen(function (QueryExecuted $query) {
Log::debug('Query: {query} | Time: {time}.', [
'query' => $query->toRawSql(),
'time' => $query->time,
]);
});
}
}
}
As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.
If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.
Laravel Package Version
1.2.1
Laravel Version
11.33.2
PHP Version
8.3.13
Database Driver & Version
No response
Description
I would like to use Pail to monitor in real time the queries that are being executed in my web system. Following documentation in: https://laravel.com/docs/11.x/database#listening-for-query-events
The session id is changed during any request and the web server sometimes returns an HTTP No Content,
Investigating the case in the code of Pail version 1.2.1, on Handler.php file lines 95 and 96 we have:
https://github.com/laravel/pail/blob/v1.2.1/src/Handler.php#L95
https://github.com/laravel/pail/blob/v1.2.1/src/Handler.php#L96
Changing
By
The problem is gone.
According to our friend Gonçalo in Issue 40 (#40) these lines make new queries in the database, infinitely activating the handler DB ::listen.
If this is the correct way to monitor queries in real time using Pail, I believe this should be a bug that should be investigated.
Steps To Reproduce
Any new Laravel projects with use DB::listen according with documentation and have Log:: inside to print queries.
The text was updated successfully, but these errors were encountered: