2011-05-10 69 views
1

如何將腳本執行錯誤傳遞給XMLRPC響應,以便我沒有發生錯誤異常?XMLRPC捕捉腳本執行錯誤並在響應中顯示它們

也許我不設置此權:

在我加入Zend_XmlRpc_Server_Fault::attachFaultException('Exception');這樣的XMLRPC服務器:

Zend_XmlRpc_Server_Fault::attachFaultException('Exception'); 
$server = new Zend_XmlRpc_Server(); 

但我仍然得到一個錯誤異常:

Fault Exception:\n651Failed to parse response 

如何將腳本執行錯誤傳遞給響應?

我也試着設置這個沒有運氣:

error_reporting(E_ALL); 
ini_set("display_errors",1); 
ini_set("xmlrpc_errors",1); 

文檔:當腳本有

Fault Exception:\n651Failed to parse response 

例如:當腳本有錯誤http://php.net/manual/en/errorfunc.configuration.php

例XMLRPC錯誤錯誤:

Fatal error: Call to undefined method 

兩者都來自相同的腳本錯誤,但我需要XMLRPC在響應中顯示致命錯誤消息,而不是給失敗的解析響應。

回答

2

可以使用set_error_handler()功能攔截腳本錯誤,而是拋出ErrorException

function exception_error_handler($errno, $errstr, $errfile, $errline) { 
    throw new ErrorException($errstr, $errno, 0, $errfile, $errline); 
} 

所以,當你調用Zend_XmlRpc_Server會::手柄():

set_error_handler('exception_error_handler'); 
$server->handle(); 
restore_error_handler(); 

編輯: ErrorException頁面中的示例#1錯誤。改用此答案中的版本。

+0

嗯,這給我一個404的faultcode和添加代碼當未知錯誤faultString:數組 ( [0] =>數組 ( [Fault代碼] => 404 [faultString] =>未知錯誤 ) ) – 2011-05-16 15:26:37

+0

如果我刪除你的代碼的功能工作得很好,添加你的代碼我得到上述評論 – 2011-05-16 15:27:09

+0

我的不好,代碼是錯誤的。我從php.net複製/粘貼了一個不好的例子。另外,我看到你特意想要捕捉一個_fatal_錯誤。這些不能被困住,你必須在它們發生之前阻止它們。你的致命錯誤發生在哪裏? – squirrel 2011-05-16 16:15:27