Trace mode is ThinkPHP’s own debugging mode. You can easily view relevant information of the current request at the bottom of the page, such as request parameters, SQL statements, etc., which is very helpful for problem location. However, in a production environment, we do not want these sensitive information to be leaked and thereby affect the system's security.. In addition, debugging mode will also bring certain performance losses, so it is necessary for us to turn it off.
ThinkPHP enables trace mode by default. We can turn off trace mode by setting the app_debug
parameter.
In the app.php
file under the config
directory, we can find the following configuration:
// 是否开启应用调试模式 'app_debug' => env('app_debug', true),
Place app_debug
The value of is set to false
to turn off the trace mode. The code is as follows:
// 是否开启应用调试模式 'app_debug' => false,
In addition to turning off the trace mode by modifying the configuration file, we can also turn off the trace mode in the application's controller (usually the base controller) add the following method:
/** * 构造函数 * * 关闭调试模式 */ public function __construct() { parent::__construct(); // 开发环境下,不关闭调试 if (config('app_debug')) { return; } // 关闭调试 config('app_trace', false); config('app_debug', false); }
This method will be called when the controller is initialized. If app_debug
is configured as false
, it will Turn off trace mode.
The above is the detailed content of How to turn off trace debugging mode in thinkphp. For more information, please follow other related articles on the PHP Chinese website!