有什麼辦法如何豐富php中的錯誤消息?我得到錯誤如更好的錯誤消息爲PHP
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 524288 bytes) in /site/lib/Zend/Db/Statement/Pdo.php on line 228
這是不是很好。至少callstack會更有幫助。
有什麼辦法如何豐富php中的錯誤消息?我得到錯誤如更好的錯誤消息爲PHP
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 524288 bytes) in /site/lib/Zend/Db/Statement/Pdo.php on line 228
這是不是很好。至少callstack會更有幫助。
那麼PHP錯誤對我來說很清楚,但是如果你想要非常詳細的信息,爲什麼不寫異常類並且定製消息包括異常消息和你自己的細節。
如果你想要更詳細的信息,那麼有一種方法來攔截函數中的錯誤信息。在那裏你可以拋出一個ErrorException
例如。這會給你更多的細節。
嘗試像下面(的catchException
是optoinal雖然)
function exception_error_handler($errno, $errstr, $errfile, $errline)
{
if (error_reporting() === 0)
{
return;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");
function catchException($e)
{
// Do some stuff
}
set_exception_handler('catchException');
嘗試安裝xdebug,看看在various settings ...
什麼是不明確的,以你在這個錯誤?它其實很清楚。您的程序使用的RAM超出允許的範圍,並且沒有剩餘RAM可供使用。爲它分配更多的內存。 – 2013-03-13 14:20:43
我認爲這個錯誤信息非常清楚並且非常重要。如果它說:「糟糕,我的日記,你試圖記憶太多,那裏再試一次,對不起。」只要處理它。要麼使腳本減少內存密集程度,要麼讓它擁有更多的內存。 – 2013-03-13 14:24:30
您可以獲得調用堆棧...嘗試搜索@ php.net? debug_backtrace http://php.net/manual/en/function.debug-backtrace.php其他的好方法是創建你自己的ExceptionHandlers ...例子在這裏:http://www.edmondscommerce.co.uk/php/PHP的自定義錯誤和異常處理,使-PHP-嚴格/ – 2013-03-13 14:21:55