
內容簡介
您有見過以下的錯誤日誌嗎?
PHP Fatal error: Allowed memory size of xxxxxx bytes exhausted (tried to allocate xxx bytes) in /var/www/wordpress/wp-includes/wp-db.php on line 2007
這表示當從數據庫檢索數據時,PHP 內存限制已用盡。在任何情況下,當您的網站具有大量數據且內部循環過多時,就會發生這種情況。
但我們想知道是哪個外掛嘗試檢索數據?
當wp-db.php引起內存限制錯誤時,Hagakure會在錯誤日誌文件中添加額外信息:
[08-May-2019 10:28:37 UTC] wpdb Error Backtrace:
#1 Kunoichi\Hagakure\DbLogger->filter_query() /app/public/wp-includes/class-wp-hook.php Line 286
#2 WP_Hook->apply_filters() /app/public/wp-includes/plugin.php Line 208
#3 apply_filters /app/public/wp-includes/wp-db.php Line 1871
#4 wpdb->query() /app/public/wp-includes/wp-db.php Line 2579
#5 wpdb->get_results() /app/public/wp-includes/class-wp-query.php Line 2979
#6 WP_Query->get_posts() /app/public/wp-includes/class-wp-query.php Line 3387
#7 WP_Query->query() /app/public/wp-includes/post.php Line 1961
#8 get_posts /app/public/wp-content/plugins/hagakure/hagakure.php Line 34
#9 {closure} /app/public/wp-includes/class-wp-hook.php Line 286
#10 WP_Hook->apply_filters() /app/public/wp-includes/class-wp-hook.php Line 310
#11 WP_Hook->do_action() /app/public/wp-includes/plugin.php Line 465
#12 do_action /app/public/wp-includes/template-loader.php Line 13
#13 require_once /app/public/wp-blog-header.php Line 19
#14 require /app/public/index.php Line 17
這個日誌總是跟隨由wp-db.php引起的內存限制致命錯誤。#8現在可以發現重複調用get_posts。
我們建議使用像CloudWatch Logs這樣的通知服務來監視日誌。
這個錯誤發生在生產環境中,您可能沒有機會看到它發生。
我們使用Hagakure和我們的託管服務,期待您能看到我們的博客文章並描述整合情況!
此外,此插件在錯誤日誌中添加了調試回溯。要將錯誤級別修改為詳細的回溯,請定義此常量:
define( 'HAGAKURE_ERROR_LEVEL', E_NOTICE | E_USER_WARNING | E_WARNING | E_USER_ERROR );
此外,如果設置SAVEQUERIES為true,將以PHP調試回溯記錄緩慢的調試日誌。這有助於您進行調試。
致謝
虛構內容的基礎文本是查爾斯·狄更斯(Charles Dickens)的 “Three Ghost Story”。文本文件修改自Gutenberg計劃之一。
外掛標籤
開發者團隊
② 後台搜尋「Hagakure – Yet Another Error Reporter」→ 直接安裝(推薦)
原文外掛簡介
Have you ever seen an error log like the one below?
PHP Fatal error: Allowed memory size of xxxxxx bytes exhausted (tried to allocate xxx bytes) in /var/www/wordpress/wp-includes/wp-db.php on line 2007
This means that PHP memory limit is exhausted while retrieving data from a database. In any case, this happens when your site has big data and makes insane loops inside.
But we want to know that which plugin tried to retrieve data?
Hagakure adds extra information to error.log file when wp-db.php causes memory limit error:
[08-May-2019 10:28:37 UTC] wpdb Error Backtrace:
#1 Kunoichi\Hagakure\DbLogger->filter_query() /app/public/wp-includes/class-wp-hook.php Line 286
#2 WP_Hook->apply_filters() /app/public/wp-includes/plugin.php Line 208
#3 apply_filters /app/public/wp-includes/wp-db.php Line 1871
#4 wpdb->query() /app/public/wp-includes/wp-db.php Line 2579
#5 wpdb->get_results() /app/public/wp-includes/class-wp-query.php Line 2979
#6 WP_Query->get_posts() /app/public/wp-includes/class-wp-query.php Line 3387
#7 WP_Query->query() /app/public/wp-includes/post.php Line 1961
#8 get_posts /app/public/wp-content/plugins/hagakure/hagakure.php Line 34
#9 {closure} /app/public/wp-includes/class-wp-hook.php Line 286
#10 WP_Hook->apply_filters() /app/public/wp-includes/class-wp-hook.php Line 310
#11 WP_Hook->do_action() /app/public/wp-includes/plugin.php Line 465
#12 do_action /app/public/wp-includes/template-loader.php Line 13
#13 require_once /app/public/wp-blog-header.php Line 19
#14 require /app/public/index.php Line 17
#15 URI: /?p=1
This log will always follow the memory limit Fatal Error by wp-db.php. Now you can find #8 calls get_posts repeatedly.
We recommend watching logs with notification services like CloudWatch Logs.
This error occurs in the productional environment, and you may not have a chance to see it occurs.
We use Hagakure with our hosting service, please look forward to seeing our blog published and describing the integration!
This plugin also adds debug backtrace to error logs. To modify the error level to a detailed backtrace, define the constant in wp-config.php or somewhere else:
define( 'HAGAKURE_ERROR_LEVEL', E_NOTICE | E_USER_WARNING | E_WARNING | E_USER_ERROR );
Besides that, if SAVEQUERIES is set true, the slow query log will be logged with PHP debug backtrace. This helps you to debug.
Acknowledgements
The base text for dummy content is “Three Ghost Story” by Charles Dickens. The text file is modified the one of Project Gutenberg.
