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

How to turn off info information output in thinkphp5

PHPz
Release: 2023-04-07 11:27:36
Original
648 people have browsed it

ThinkPHP5 is a very popular PHP development framework. Its excellent code design and rich functions are loved by many developers. However, during the development process, we found that many times the debugging information of the framework is not very useful, and sometimes the debugging information leaks some sensitive information. Therefore, turning off info has become an essential skill for many developers.

This article will tell you how to turn off the info information output of the ThinkPHP5 framework without affecting development efficiency.

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 SQL statement execution and running time of the current page at the bottom of the page Waiting for debugging information
  3. When an execution error occurs, detailed error information is output to facilitate debugging

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

2. Turn off info

Turning off info is very simple. You only need to set the app_debug configuration item to false in app.php in the configuration file to turn off the info information output. The sample code is as follows:

return [
    'app_debug' => false
];
Copy after login

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');
});
Copy after login

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

3. Summary

In actual development, the info information output by the ThinkPHP5 framework is usually intolerable to programmers. Too much info often results in unnecessary page loading times and output information.

It is very simple to turn off the info information of the ThinkPHP5 framework. You only need to set the app_debug configuration item to false in the configuration file. However, if you need to output the execution status of SQL for debugging when necessary, you can use the above code to set it up.

I hope that this article can help you better complete the development work based on the ThinkPHP5 framework.

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!

source:php.cn
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