Home  >  Article  >  PHP Framework  >  How to turn off info information output in thinkphp5

How to turn off info information output in thinkphp5

王林
王林forward
2023-06-03 11:49:081348browse

1. The role of info

Before we start to close info, we need to understand its role. In the ThinkPHP5 framework, there are three main forms of info information output:

  1. Displays the currently accessed URL and request parameters

  2. Displays the current URL at the bottom of the page Debugging information such as the page's SQL statement execution and running time

  3. When an execution error occurs, detailed error information is output to facilitate debugging

Although It seems helpful, but for real developers, most of the info information is not very practical. Often, what we need is some more concise output so we can better focus on development.

2. Close info

Close info is very simple. You only need to set the app_debug configuration item to false in app.php in the configuration file to close info. Information output. The sample code is as follows:

return [
    'app_debug' => false
];

After this setting, by default, the page will no longer display the current URL and request parameters, and will not output SQL statement execution status and error information. Of course, you can turn info back on in the framework's debug mode if you need to.

In addition, if you need to output the SQL execution status for debugging during the development process, you can turn on the SQL log as follows:

Db::listen(function($sql, $time, $explain){
    // 记录SQL
    trace($sql . ' [' . $time . 's]', 'sql');
    // 查看性能分析结果
    trace($explain, 'explain');
});

In this way, you can output SQL in the trace folder of the program Log information.

The above is the detailed content of How to turn off info information output in thinkphp5. For more information, please follow other related articles on the PHP Chinese website!

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