Persistent HTTP Connections and Flex Data Services w/ Zend_Amf

10 12 2009

I encountered some time ago, what I was convinced was a bug in the Zend_Amf protocols. It seemed to me that something was wrong with the ACL, or the way that things were being called. And it still may be, I don’t know. Here is what I was experiencing.

Logical System:

Lets say I had a remote method call getDetails($params) that called a remote data service on my server, which would then do some calculations, maybe a database lookup or two, and send information back to the client. Let’s also say that I didn’t want anyone to be able to call this method, so it internally utilizes Zend_Acl to manage access control.


When getDetails is called once at a time, with a gap in between calls everything works fine. You can even call it twice simultaneously, as internally Flash Player can handle two open HTTP protocols. The issue comes when you call it, say three or more times simultaneously. When this happens, the third and above call will fail due to Flash Player using what is known as a persistent HTTP connection. Now let me clarify. It will not always fail, but if you are using ACL, the initAcl function will be called with each function call, NOT each connection. That is when it fails. ACL cannot add a duplicate permission (same user, same permission group, etc.) I believe this is caused by the persistent connection, as your Zend session will remain in memory on the server since the connection was never terminated.


There are two feasible solutions that I see at this point. First, set an internal flag to check if the ACL has already been configured for that connection. The second option is that you can accomplish the same result, (albeit incredibly slower and more processor intensive) by wrapping every call to add to the ACL (in your initAcl function) in a try catch block. There is a third option. However, I don’t consider it highly feasible (as I don’t have a clue how to do it, but to be honest I haven’t taken the time to try to figure it out.) Change the HTTP header that Flash Player sends to be a version of HTTP that does not support persistent connections.


This may be a bug, maybe its my own programming incompetence. I’m not sure. Let me know what you think in the comments.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: