Home >PHP Framework >ThinkPHP >Handling thinkphp6 turning off debugging mode (APP_DEBUG=false) error reporting problem

Handling thinkphp6 turning off debugging mode (APP_DEBUG=false) error reporting problem

藏色散人
藏色散人forward
2020-12-25 16:09:525047browse

The following is the thinkphp framework tutorial column to introduce to you how to turn off the debug mode of thinkphp6 ( APP_DEBUG=false) error handling, I hope it will be helpful to friends in need!

Introduction


Hello everyone, as a pseudo-phper who came into contact with PHP in 2009, started using the TP framework in 12 years, and has not written a complete code since 16 years. Engineer, when I wrote this LOG, I felt really mixed emotions and sighing. I wasted a lot of time and did not make any contribution to the progress of PHP or TP;
The core purpose of this article is not the problem itself ( Because this problem is not difficult to solve) I would like to share my personal thoughts on dealing with similar problems. I hope it can provide a little help to those who need it. Corrections are welcome if my ability is limited.

Problem description


Close debugging problem:

  • tp6 adds .env configuration mode, and issues with the official environment appear;
  • Development and testing environment APP_DEBUG = TRUE, everything is normal;
  • After the official release, set APP_DEBUG = FALSE to report a 500 error;

Benefits of debugging mode:

  • The advantage of debugging mode is: when logging is turned on, any error information and debugging
  • information will be recorded in detail to facilitate debugging;
  • will record the entire execution process in detail;
  • Template modifications can take effect immediately;
  • Use the Trace function to better debug and detect errors;
  • Detailed exception information will be displayed when an exception occurs;

Open and close methods

Edit .ENV file

//Set to enable debugging mode
APP_DEBUG = FASLE
//Others Environment variable settings
// …

Solution ideas


  • step1 Reproduce the problem, the shortest answer Method, turn off debugging mode in the test environment;
APP_DEBUG = falseENV = testing.....
  • step2 Turn on the log, turn off debugging errors will not be printed, so you need to turn on php file error recording
#编辑php.ini文件,开启log_errors = On
error_log = /data/logs/php7/php_error.log
  • step3 Check the problem, check php_error.log, and see what the specific description of the problem is
#php error log 错误如下,路径需要换成您自己的,非必要信息略...PHP Fatal error:  Uncaught $YOUR_REAL_PATH\think\exception\ErrorException: Invalid argument supplied for foreach() in vendor/topthink/think-annotation/src/CachedReader.php:99
Stack trace:#0 /$YOUR_REAL_PATH/vendor/topthink/think-annotation/src/CachedReader.php(99): think\initializer\Error->appError(2, 'Invalid argumen...', '...', 99, Array)
  • step4 Solve the problem and find that the problem is actually half solved;
既然已经找到错误信息了,那么问题就比较好处理了:

option1 如果着急上线,可以先开启调试模式
option2 如果项目没用用注解可以关掉;
option3 如果1和2都不行,那么久仔细研究下CachedReader.php,看看bug出在哪

Solution

Option 1 Emergency solution, enable debugging mode in the online environment

APP_DEBUG = trueENV = live

Option 2 Short-term solution, in config/annotation.php Turn off the annotation function

e3fa5384b17edd13525c70273ec9212e [
        'enable'     => false,
        'namespaces' => [],
    ],
    'route'  => [
        'enable'      => false,
        'controllers' => [],
    ],
    'ignore' => [],];

Option 3 Long-term solution, check the CachedReader.php code why the error is reported?

# 第8行引入错误
 use think\Cache;
 更改为========================>
 use think\cache\Driver;
 # 第143行 fetchFromCache 方法错误
  private function fetchFromCache($cacheKey, ReflectionClass $class)
   {
       if (($data = $this->cache->get($cacheKey)) !== false) {
           if (!$this->debug || $this->isCacheFresh($cacheKey, $class)) {
               return $data;
           }
       }
       return false;
   }更改为========================>
   private function fetchFromCache($cacheKey, ReflectionClass $class)
   {
       if ((!$this->debug || $this->isCacheFresh($cacheKey, $class)) && $this->cache->has($cacheKey)) {
           return $this->cache->get($cacheKey, false);
       }
       return false;
   }

Option 4 Wanmei solution, I hope everyone can habitually pay attention to plug-in updates and BUG

#解决当前问题的方式命令行更新如下,也可以用IDE更新哦$composer update topthink/think-annotation

Problem Summary

1. Don’t have server login permission?
Directly ini_set("display_errors",1) at the code level
2. What should I do if there are multiple load balancing machines?
You can bind hosts to locate the error to a machine

The above is the detailed content of Handling thinkphp6 turning off debugging mode (APP_DEBUG=false) error reporting problem. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete
Previous article:About thinkphp using mqttNext article:About thinkphp using mqtt