Question

What is the best method for communication between Flex and PHP?

In the past, we used AMFPHP with AS2, and it worked great for the most part (advantage of AMFPHP is that it also has a JSON mode that can let you seamlessly use the same remote PHP with either Javascript or Actionscript frontends).

However, it seems like AMFPHP isn't realy maintained anymore. So what do people recommend to replace it? So far, what I've found is:

  1. Zend_AMF (looks too complex for us, we're not using the Zend framework otherwise)
  2. AMFPHP (there were some updated made to support Flex, and it seems fairly stable, but not sure on long-term support)
  3. XML (AS3 has nice XML handling routines, but it's more of a pain on the PHP side)
  4. WebORB (I have no experience with this)
  5. Roll-our-own using JSON or some other data-to-text serialization system (php's serialize(), XML, etc etc)

Mostly I'm leaning towards AMFPHP, even because of the downsides, since that's what I'm used to. Any reason I should consider switching to something else?

Was it helpful?

Solution

If you want to have fast and efficient communication, I highly recommend sticking with an AMF protocol instead of a REST or JSON custom format.

ZendAMF is actually not very confusing. Watch the introduction tutorial on GotoAndLearn, it's quite simple.

And just so you know, some of the developers from AMFPHP moved to work on ZendAMF. So in a sense, ZendAMF is the continuation of AMFPHP.

OTHER TIPS

ZendAMF Good short read - http://theflashblog.com/?p=441

For me this is no brainer. The Zend framework is one of the best php frameworks out there, and now you can talk to Flash clients. Top it off with Adobe support, that's a done deal in my book.

Alternatives :

WebORB for php http://www.themidnightcoders.com/products/weborb-for-php

AMFPHP http://www.amfphp.com If you read the url above, you'll probably know why this is no longer on my radar.

I can't tell you what's best (because that's probably somewhat subjective anyway), but what I can do is tell you about a recent project of mine.

Since this was a very rich web app, and data requests to the server would be frequent, I wanted to make sure the size of the requests were as small as possible. This mean choosing JSON as the format.

Next, becuase of the nature of the application and the fact that my flash/flex developers were 1000 miles away, I needed an API that was simple and stateless. This ultimately led us to HTTP + REST.

So, the communication layer of my app is a simple Zend Framework powered set of REST resources with URIs like

user/10
review/15
location/8/reviews

They all return JSON. There's a common JSON format for all errors, as well (exceptions are trapped and converted into JSON objects) so that the flash client can easily handle failure.

If you're not using a framework like Zend, regular ol AMFPHP is still great, if for no other reason than that it's simple. I think if you feel comfortable with it, why not go for it? The thing about the role of these AMF interfaces is that they really don't need to do too much, and what AMFPHP does have in class mapping, recordset parsing into ArrayCollection, great performance.... it even does well with XML, since it gets compressed. The service browser combined with Charles has covered me as well.

I haven't been able to make much sense of how the ZendAMF effort relates to the original AMFPHP. While I can dig, I'm just saying that in following the AMFPHP mailing list on Nabble, reading Wade Arnold's blog... it's just not entirely clear.

You should consider using Zend AMF. The Zend Framework is designed to be a pick and chose framework so it is completely OK to pick a single component (in this case Zend AMF) for your application.

Zend AMF is extremely easy to use. All you have to do is specify the functions/classes you want to expose and specify class mapping to your action-script classes. Everything else is pretty much transparent.

This link is a screencast showing how to use WebORB for PHP WDMF (WebORB Data Management for Flex).

http://www.themidnightcoders.com/products/weborb-for-php/developer-den/screencasts/weborb-data-management-for-flex-and-php.html

In all projects involving Flash and PHP backend, I worked with either AMFPHP or XML requests.

AMFPHP really simplifies understanting the application for future maintenance, although it ties the whole thing to that specific technology and involves some additional overhead on the server side - to create all needed classes.

As per XML, well, what you gain here are standard REST webservices and it doesn't depend on Flash (you could pull data from a desktop app as well, for example, whereas using JSON or any other technology dependent on browsers don't allow for that).

If you want 100% future "support", then I'd recommend what doesn't need any support at all: XML.

XML on PHP can be a lot simpler with SimpleXML.

I'd just use JSON as your returns for simple calls against your PHP api.

I would definitely go for WebORB. I used it with .NET in a previous job I had and it was a joy to code with. Its ease of use and its well thought management console make it very fast to learn, and its documentation is very complete; I know it's tempting to stay with AMF just because it's what you already know, but I believe it's worth to give WebORB a try.

Take a look at this screencast for Actionscript generation with PHP, it's quite fancy.

Cheers.

PHP has a pretty good serialize() function, so for a recent project I did (high scores for a game), I used Sephiroth's Serializer. It makes the serialization on Flash's side nearly as easy as it is in PHP. Serializer also deals with datatypes (unlike json/xml) like AMF.

Downside--it's not as compact as AMF, but that's nothing gzip compression can't handle.

AMF has a pretty situational advantage. If you're looking to transfer large and complex Object, by all means go with AMF. But little does people know about the overhead that AMF carries when you're transferring small objects. If you're only transferring an object with 3 properties, using AMF can triple your payload size.

On a side note, I'm a big advocate of RESTful architecture. Since JSON and AMF are both just representations, you can build a REST service that accepts both, and negotiate the actual representation with your client at runtime.

"If you want to have fast and efficient communication, I highly recommend sticking with an AMF protocol"

And if you want a fast, efficient, and generalized communication, go with json. Then your web service will be available to flash, ajax, or regular http requests.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top