天天看點

XDebug 自動開啟PHP Stack Trace, 導緻PHP Log 超1G

昨天早上突然發現測試伺服器空間滿了,用du挨個檔案夾檢視,發現是php debug log占地極大,有的log直接有1g,打開後發現極其多的php

stack trace.

立刻到主伺服器檢視,主伺服器日志也400多m的日志,幸好主伺服器空間足夠。

那麼多stack trace,可以肯定之前是沒有的,挨個檢視日志,是某一天早上一個時刻發生的。

解決方案:

1. 難道是之前更新php導緻,到網上搜尋php stack

trace,所有的都是顯示如何打開,卻沒有如何關閉的。仔細查找php的參數,隻找到ignore_repeated_sources和ignore_repeated_error這兩個看似有關的東西,更改後也不頂用。

2. 如果不是更新php所緻,再仔細想這幾天做了什麼 改動,哪些是和php trace有關的,想起xdebug.

,先嘗試把xdebug删除,ok,問題消失了。肯定是xdebug的問題了,開始的時候沒有直接找xdebug的官方文檔,利用phpinfo把xdebug所有的參數都打出來,先猜是哪個參數,試了幾個都不頂用,

後來才靜下心來看看xdebug的官方文檔吧,發現了如下話語:

when xdebug is activated it will show a stack trace

whenever php decides to show a notice, warning, error etc. the information that

stack traces display, and the way how they are presented, can be configured to

suit your needs.

有戲,再繼續找,發現了一個名稱和用途你如何也聯系不上的變量"xdebug.default_enable",還真就是這個參數來控制了,如下。

xdebug.default_enable

type: boolean, default value: 1

if this setting is 1, then stacktraces will be shown by

default on an error event. you can disable showing stacktraces from your code

with.

as this is one of the basic functions of xdebug, it is advisable to leave this

setting set to 1.

這個問題幾乎折騰一天,心得:碰到意外問題時要冷靜,雖然影響了多原有計劃,但如果問題是嚴重的問題就一定要排除萬難先解決了再說,不然會形成習慣。另外,使用一些現成功能子產品時,在在最衩進行搜尋無果後,得靜下心來仔細閱讀官方文檔。