2013-10-03 34 views
0

我的PHP Web的應用程序有時會返回此Fatal error on Line XXX由於像極慢速連接速度快的原因。儘管這種情況很少發生,比如1000次中的1次,但我希望在瀏覽器上避免出現這種輸出。我在服務器端爲一些功能做錯誤日誌記錄。所以,我不想完全禁用錯誤報告。只是我不想將其展示給最終用戶。如何避免或限制PHP錯誤輸出

+1

您可以在過程中添加'@',它可以抑制錯誤消息。 –

回答

2

要禁用任何錯誤顯示到你的頁面的用戶,設置

display_errors = Off 

在php.ini(這是推薦的設置進行生產無論如何!)或

ini_set('display_errors', 0); 

在您的PHP。

display_errors設置僅影響網頁上的輸出;它不會影響可能配置的日誌文件;那裏的信息仍然會被記錄下來。

有關配置錯誤報告PHP文檔:http://php.net/manual/en/errorfunc.configuration.php

注:通過這裏的其他用戶提到的error_reporting設置,會,就我所知,影響各種錯誤報告(即還什麼報道一個可能配置的日誌文件)。如果您將error_reporting設置爲0,您也不會獲得任何日誌條目。如果你想記錄的東西到日誌文件,但它不會顯示給用戶,該display_errors設置是要走的路。

1

在該頁面的開始寫

error_reporting(0); 
+0

將禁用錯誤的任何報告(也在日誌文件) – codeling

3

上關閉使用error_reporting各種例子..

<?php 

// Turn off all error reporting 
error_reporting(0); 

// Report simple running errors 
error_reporting(E_ERROR | E_WARNING | E_PARSE); 

// Reporting E_NOTICE can be good too (to report uninitialized 
// variables or catch variable name misspellings ...) 
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); 

// Report all errors except E_NOTICE 
// This is the default value set in php.ini 
error_reporting(E_ALL^E_NOTICE); 

// Report all PHP errors (see changelog) 
error_reporting(E_ALL); 

// Report all PHP errors 
error_reporting(-1); 

// Same as error_reporting(E_ALL); 
ini_set('error_reporting', E_ALL); 

?> 

注:您可以將或include()它在你不想要的任何文件以明確的錯誤。或者如果你想完全消除它。去調整php.ini文件。

線在你的php.ini找到的調整和關閉的error_reporting。

ini_set('display_errors', 'On'); //change to Off 
     error_reporting(E_ALL); // change to 0 

欲知更多信息:: PHP.NET

+0

感謝。這很有用。但是ini_set('display_errors',0);在這裏爲我做了詭計。 – emotionull

+0

@Kaii btw ...如果我做error_reporting(0);然後嘗試執行error_log('some msg'),它會起作用嗎? – emotionull

+0

@nyarlathotep謝謝。我從其他stackoverflow問題得到解決方案。我的分數是低,所以不能給予好評,現在:( – emotionull

0

爲避免這樣的問題,您可以設置max_execution_time = 1024M以避免數據生成速度緩慢並且隱藏錯誤,因此php.ini文件中的錯誤報告必須可能爲error_reporting = 0。

或者乾脆:

PHP Code 
ini_set('max_execution_time',1024M); 
error_reporting(0); 

PHP Ini Settings 
max_execution_time=1024M 
error_reporting=0 

希望它能幫助。

0

的error_reporting(0);只有當你不使用set_error_handler('my_function')時纔有效。如果這是你的情況,你可以在'my_function'中隱藏錯誤信息。