2017-05-03 15 views
0

我想在Drupal網站的根目錄下創建一個簡單的PHP狀態文件。該文件將由諸如Nagios之類的監控系統調用。我想完全自定義輸出並在錯誤消息中添加一些額外的細節(作爲純文本字符串)。如何禁用所有Drupal 7錯誤和異常處理程序

我試過下面的代碼:

define('DRUPAL_ROOT', __DIR__); 
require_once realpath(DRUPAL_ROOT . '/includes/bootstrap.inc'); 
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 

restore_exception_handler(); 
restore_error_handler(); 

function exception_handler($exception) { 
    echo "Uncaught exception: " , $exception->getMessage(), "\n"; 
} 
set_exception_handler('exception_handler'); 

function myErrorHandler($errno, $errstr, $errfile, $errline) 
{ 
    echo "PHP Error: [$errno] $errstr<br />\n"; 
    return true; 
} 
$old_error_handler = set_error_handler("myErrorHandler"); 

try { 
    db_query('SELECT COUNT(nid) FROM {node}'); 
    echo 'ok'; 
} 
catch (\PDOException $e) { 
    echo "Database problem"; 
} 
catch (Exception $e) { 
    echo "Unexecpted error: " . $e->getMessage(); 
} 

然而,當我嘗試禁用數據庫(通過停止服務),出現在HTML格式的Drupal的自定義錯誤。

回答

0

您必須去admin/config/development/logging並檢查選項None以隱藏錯誤