


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
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
<?phpreturn [ 'inject' => [ '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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses key considerations for using ThinkPHP in serverless architectures, focusing on performance optimization, stateless design, and security. It highlights benefits like cost efficiency and scalability, but also addresses challenges

ThinkPHP's IoC container offers advanced features like lazy loading, contextual binding, and method injection for efficient dependency management in PHP apps.Character count: 159

The article discusses implementing service discovery and load balancing in ThinkPHP microservices, focusing on setup, best practices, integration methods, and recommended tools.[159 characters]

The article discusses ThinkPHP's built-in testing framework, highlighting its key features like unit and integration testing, and how it enhances application reliability through early bug detection and improved code quality.

The article outlines building a distributed task queue system using ThinkPHP and RabbitMQ, focusing on installation, configuration, task management, and scalability. Key issues include ensuring high availability, avoiding common pitfalls like imprope

The article discusses using ThinkPHP to build real-time collaboration tools, focusing on setup, WebSocket integration, and security best practices.

Article discusses using ThinkPHP for real-time stock market data feeds, focusing on setup, data accuracy, optimization, and security measures.

ThinkPHP benefits SaaS apps with its lightweight design, MVC architecture, and extensibility. It enhances scalability, speeds development, and improves security through various features.
