Home >PHP Framework >Laravel >View sql in real time on the console

View sql in real time on the console

藏色散人
藏色散人forward
2019-09-06 11:50:053587browse

listen-sql A tool to see real-time sql operations on the console

To print sql in Laravel, the past practice is often to listen through DB::listen, and then pass Log::info is written to the log.

If we want to check the log written in this way, we usually go to the storage folder to find the log file of the day, and then open it. The bad thing is that if it is opened in the editor, it will often not update in real time. After the request is completed, you may need to switch to other tabs and switch back to update. At the same time, too many sql logs will be mixed with other logs, which will appear a bit confusing.

In addition, you can also run tail -f storage/logs/xx.log to view the log output in real time. The disadvantage of this is that if log => 'daily' is defined in config/app.php, a new file name must be entered every day.

Now, we can use only one command to implement the sql operation in the monitoring application.

View sql in real time on the console

Installation

1. Install through composer (eleven26/listen-sql).

composer require "eleven26/listen-sql:~1.0.3"

2. Register Service Provider

Laravel: Modify the file config/app.php, Laravel 5.5 does not require

'providers' => [
    //...
    Eleven26\ListenSql\ListenSqlServiceProvider::class,
],

Lumen: Modify the file bootstrap/app.php

$app->register(Eleven26\ListenSql\ListenSqlServiceProvider::class);

Use

php artisan listen-sql:start

At this step, when you refresh the page, you can see the sql statement in the console

More Laravel related technologies Article, please visit the Laravel Framework Getting Started Tutorial column to learn!

The above is the detailed content of View sql in real time on the console. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete