Home >PHP Framework >ThinkPHP >Handling thinkphp6 turning off debugging mode (APP_DEBUG=false) error reporting problem
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
- 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;
Edit .ENV file
//Set to enable debugging mode
APP_DEBUG = FASLE
//Others Environment variable settings
// …
Solution ideas
APP_DEBUG = falseENV = testing.....
#编辑php.ini文件,开启log_errors = On error_log = /data/logs/php7/php_error.log
#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)
既然已经找到错误信息了,那么问题就比较好处理了: option1 如果着急上线,可以先开启调试模式 option2 如果项目没用用注解可以关掉; option3 如果1和2都不行,那么久仔细研究下CachedReader.php,看看bug出在哪
Solution
APP_DEBUG = trueENV = live
e3fa5384b17edd13525c70273ec9212e [ 'enable' => false, 'namespaces' => [], ], 'route' => [ 'enable' => false, 'controllers' => [], ], 'ignore' => [],];
# 第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; }
#解决当前问题的方式命令行更新如下,也可以用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!