Home > PHP Framework > ThinkPHP > How to turn off trace debugging mode in thinkphp

How to turn off trace debugging mode in thinkphp

PHPz
Release: 2023-06-02 22:53:55
forward
1760 people have browsed it

Why should we turn off trace mode?

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.

How to turn off trace mode?

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),
Copy after login

Place app_debug The value of is set to false to turn off the trace mode. The code is as follows:

// 是否开启应用调试模式
'app_debug' => false,
Copy after login

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

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!

Related labels:
source:yisu.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