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

藏色散人
Release: 2021-01-05 09:07:51
forward
5056 people have browsed it

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.....
Copy after login
  • 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
Copy after login
  • 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)
Copy after login
  • step4 Solve the problem and find that the problem is actually half solved;
既然已经找到错误信息了,那么问题就比较好处理了:

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

Solution

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

APP_DEBUG = trueENV = live
Copy after login

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

<?phpreturn [
    &#39;inject&#39; => [
        &#39;enable&#39;     => false,
        &#39;namespaces&#39; => [],
    ],
    &#39;route&#39;  => [
        &#39;enable&#39;      => false,
        &#39;controllers&#39; => [],
    ],
    &#39;ignore&#39; => [],];
Copy after login

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

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

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

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!

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