调用SOAP的XMLRPC需要返回响应而不是崩溃/死亡

时间:2010-12-30 17:38:21

标签: php soap exception-handling try-catch xml-rpc

所以我有一个在Zend PHP中开发的XMLRPC,它调用SOAP请求来启动另一个进程(SOAP不是我的脚本,而是XMLRPC)。

在SOAP请求期间,如果找不到主机,则有时会导致我的XMLRPC调用崩溃。 如何使用响应而不是错误返回XMLRPC请求?逻辑看起来不错吗?我知道所有的功能都有效,我得到了我想要的响应(有时),但我需要确保脚本不会崩溃。有什么想法吗?提示?

这就是我所拥有的

try {
   $soap_call = new ReportSoapClient();
   $soap_call->RunReport();
} catch(Exception $e) {
   // Set the Error Alert Email Message
   $this->setErrorAlertMessage($this->getErrorAlertMessage()."ERROR: SOAP Exception: ".$e->getMessage());
   // Send the Email
   $this->sendErrorAlertEmail();

   // This set the XMLRPC Response 
   $this->setXMLRPCResponse('Code: '.$e->getCode().' Message: '.$e->getMessage());
   // This is a logger
   $this->debug('Code: '.$e->getCode().' Message: '.$e->getMessage());
   // Return the XMLRPC Response
   return $this->getXMLRPCResponse();
} 

以下是我收到的电子邮件:

ERROR: SOAP Exception: Could not connect to host

这是崩溃时遇到的错误(有时只发生,为什么???):

Fatal error: Uncaught exception 'Zend_Http_Client_Adapter_Exception' with message 'Read timed out after 10 seconds' in /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php:512
Stack trace:
#0 /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php(330): Zend_Http_Client_Adapter_Socket->_checkSocketReadTimeout()
#1 /usr/share/php/libzend-framework-php/Zend/Http/Client.php(989): Zend_Http_Client_Adapter_Socket->read()
#2 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(280): Zend_Http_Client->request('POST')
#3 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(361): Zend_XmlRpc_Client->doRequest(Object(Zend_XmlRpc_Request))
#4 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client/ServerProxy.php(93): Zend_XmlRpc_Client->call('system.multical...', Array)
#5 [internal function]: Zend_XmlRpc_Client_ServerProxy->__call('multicall', Array)
#6 /path/to/xmlrpc.client.php(70): Zend_XmlRpc_Client_ServerProxy->multicall(Array)
#7 {main}
  thrown in /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php on line 512

increased the timeout to 30 seconds(< - 链接:如果你需要看看如何)然后我有时会得到这个:(再次为什么???):

Fatal error: Uncaught exception 'Zend_Http_Client_Adapter_Exception' with message 'Read timed out after 30 seconds' in /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php:512
Stack trace:
#0 /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php(330): Zend_Http_Client_Adapter_Socket->_checkSocketReadTimeout()
#1 /usr/share/php/libzend-framework-php/Zend/Http/Client.php(989): Zend_Http_Client_Adapter_Socket->read()
#2 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(280): Zend_Http_Client->request('POST')
#3 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(361): Zend_XmlRpc_Client->doRequest(Object(Zend_XmlRpc_Request))
#4 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client/ServerProxy.php(93): Zend_XmlRpc_Client->call('system.multical...', Array)
#5 [internal function]: Zend_XmlRpc_Client_ServerProxy->__call('multicall', Array)
#6 /path/to/xmlrpc.client.php(23): Zend_XmlRpc_Client_ServerProxy->multicall(Array)
#7  in /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php on line 512

以下是有时返回的内容(这是所需的响应):

Code: 0 Message: Could not connect to host

1 个答案:

答案 0 :(得分:0)

这是SOAP进程错误输出并没有正确抛出错误。啊