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

View sql in real time on the console

藏色散人
Release: 2019-09-06 11:50:05
forward
3612 people have browsed it

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"
Copy after login

2. Register Service Provider

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

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

Lumen: Modify the file bootstrap/app.php

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

Use

php artisan listen-sql:start
Copy after login

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!

Related labels:
sql
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template