Home >PHP Framework >ThinkPHP >How to turn off info information output in thinkphp5
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:
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 ];
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.
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!