Table of Contents
Close debugging problem:
Benefits of debugging mode:
Open and close methods
Option 1 Emergency solution, enable debugging mode in the online environment
Option 2 Short-term solution, in config/annotation.php Turn off the annotation function
Option 3 Long-term solution, check the CachedReader.php code why the error is reported?
Option 4 Wanmei solution, I hope everyone can habitually pay attention to plug-in updates and BUG
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

Dec 25, 2020 pm 04:09 PM
thinkphp6

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What Are the Key Considerations for Using ThinkPHP in a Serverless Architecture? What Are the Key Considerations for Using ThinkPHP in a Serverless Architecture? Mar 18, 2025 pm 04:54 PM

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

What Are the Advanced Features of ThinkPHP's Dependency Injection Container? What Are the Advanced Features of ThinkPHP's Dependency Injection Container? Mar 18, 2025 pm 04:50 PM

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

How to Implement Service Discovery and Load Balancing in ThinkPHP Microservices? How to Implement Service Discovery and Load Balancing in ThinkPHP Microservices? Mar 18, 2025 pm 04:51 PM

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

What Are the Key Features of ThinkPHP's Built-in Testing Framework? What Are the Key Features of ThinkPHP's Built-in Testing Framework? Mar 18, 2025 pm 05:01 PM

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.

How to Build a Distributed Task Queue System with ThinkPHP and RabbitMQ? How to Build a Distributed Task Queue System with ThinkPHP and RabbitMQ? Mar 18, 2025 pm 04:45 PM

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

How to Use ThinkPHP for Building Real-Time Collaboration Tools? How to Use ThinkPHP for Building Real-Time Collaboration Tools? Mar 18, 2025 pm 04:49 PM

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

How to Use ThinkPHP for Building Real-Time Stock Market Data Feeds? How to Use ThinkPHP for Building Real-Time Stock Market Data Feeds? Mar 18, 2025 pm 04:57 PM

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

What Are the Key Benefits of Using ThinkPHP for Building SaaS Applications? What Are the Key Benefits of Using ThinkPHP for Building SaaS Applications? Mar 18, 2025 pm 04:46 PM

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

See all articles