Join Drew Falkman for an in-depth discussion in this video Intro to Flex remoting, part of Creating Data-Driven Applications with Flex 4.5 and PHP.
While HTTP Service is a handy and open-platform way for interacting with server-side data, when you're working with PHP, you have the option of a faster and better way: Action Message Format, or AMF. Instead of sending the data back and forth in XML or strings that need parsing, AMF is a binary format that speeds this serialization process and shrinks the packet size of the data traveling to and from the client. Let's rewind a little and take a look at the different ways you can access data in Flex. The HTTPService is typically going to get XML, or possibly JSON or text data, from some URL over the web.
It may pass parameters or it may not. WebServices use WSDL and SOAP Standards-- these are XML standards--to pass data back and forth from the web. Essentially, you're calling remote operations, and it's using XML to serialize and de-serialize, as well send the data to and from. And lastly, we have the RemoteObject. RemoteObject is AMF, which is a binary process. The similarities of all these is that they all handle the results and faults in the same basic way.
So regardless of which one you use, your ActionScript is quite similar, but which one you use can affect your performance radically. The advantage of using a remote object in AMF is it's a binary format. So the size of packets in transit are much smaller, especially than XML. The serialization and de-serialization is also speeded up on both sides. AMF also allows you to have data types. When you return XML results, by default they are un-typed objects and possibly repeating notes will be turned into array collections.
Other than that, nothing else will come through. When you are working with AMF, you can send your own type data. Strings and numbers will be typed as well, but you can create the value object pattern, which allows you to have PHP classes in ActionScript classes mapped to one another, and then they can be interchanged between the two environments universally. James Ward did a test of AMF results versus a number of other different types of service calls, and you can see by far AMF is the fastest of all these different types of data calls.
In fact, I still haven't even gotten results of this Ajax JSON call, even though I did it minutes ago. There are number of different libraries you can use to access PHP via AMF. SabreAMF and AMFPHP are both simple lightweight protocols. We chose to cover AMFP in this particular course. WebORB is another library available. It's popular in the .NET world, and it also provides some code generation. Lastly ZendAMF, this is what's bundled with Flash Builder for PHP, and this is the primary way that we are going to end up using Flash Builder.
If given the choice, AMF is generally the preferred way of accessing data remotely from server environments, including PHP. The binary format is generally lower overhead and allows variables to be typed between the server and client environment. There are a few adapters that can be used, and we are going to look at some of those in next the few movies.
- Understanding session management
- Accessing RESTful services
- Customizing service calls by passing parameters
- Handling raw XML and JSON data
- Exposing a PHP class as a Flex service
- Generating PHP services with Flash Builder
- Debugging in Flash Builder and Zend Studio
- Exchanging data from PHP to Flex and back
- Building a Master-Detail page
- Implementing pagination
- Creating a synchronized database in AIR
- Using server-side session data