ZF-5118: Zend Amf does not properly handle exceptions thrown by a service


When an exception is thrown inside a service class, Zend_Amf will catch it, but it will not return a "proper" AMF response to the client. This really gets in the way of properly debugging the service. After an exception is thrown, the output changes to: "

Zend Amf Endpoint

" which can not be parsed by a client expecting an AMF response.

It's not possible to make Zend_Amf not catch exceptions, so it's hard to get around this.


set component name and auto assign again

I suppose what I'm trying to say is, it would be an extremely welcome addition to Zend_Amf if it had some kind of "debug" mode, where it has ways of recording php errors/thrown exceptions. Right now it pushed an (empty!) errormessage to the client, which makes it impossible to debug on that end. You can't put a try/catch block around the server code either, because it catches any exceptions internally.

I agree thanks for your advice. I will add it into the next minor release. Please continue giving workflow feedback like this!

This is already resolved by the setProduction(false) trick, right?

Yes you get the detailed php error message through setProduction(false). Otherwise you will just receive the error code.

Can you confirm it doesn't give back "

Zend Amf Endpoint

" as the body even with setProduction(true) ? Because that results in errors on the flex side

I will write an example to confirm and add it to the documentation.


SetProduction(false) trick is nice but no need to explain that you can't apply it in production environment. So an evident question appears: how do you track errors on production environment? I found the answer to be "you can't".

I bet a lot of developers would love to have ability to log errors in this case. So maybe consider something similar to Zend MVC's ErrorController solution?

I will check out how they implemented it.

It would be nice to at least have the option to set a callback that will get called when an exception is caught by the AMF server. That and a proper set_error_handler() would be enough to log problems to disk. The option to be able to log the response before it is encoded to disk is also nice. To debug this sort of thing now I have to "fake" a request using my browser and log the response there.

Anything that could be added to the documentation around proper debugging techniques and solutions would be very welcome. I find trying to resolve what when wrong on the PHP side from within Flex a little more painful than it should be. To make matters worse there seem to be specific scenarios where Zend AMF fails, no errors arise in the PHP server logs, and the Flex client just barfs up its Delivery in Doubt messages. These silent errors are very aggravating when trying to resolve a bug on a deadline.

In traditional PHP+HTML development the browser tells you right away if something is wrong on the server. Inside flex the errors don't come trough as transparently.

Totally agree with Gordon.

As a possible solution I propose to surround the execution of operation block inside Zend_Amf with try-catch and thus accumulate exceptions, than throw them when it comes to Zend_Amf_Server::handle() calling. The behaviour of this could be controlled by some additional settings to Zend_Amf.

As I needed the discussed functionality and to get this issue rolling I propose the attached modification to the Server.

Regards Stefan

Some time ago I created ExtraLoggingZendAmfServer class. It has one additional method setExceptionHandler which gets class name or instance of class and the name of the method in this class to execute when exception happens. See here: […]