Flash Remoting with PHP
After delving into a bit of research today into the advancements of the Adobe Flex framework I came across a way to perform Flash Remoting with PHP via an Open Source package called AMFPHP. Flash Remoting is a bridge between the Flash movie and your web application server. Typically this can be done with a REST-like remote procedure call where you invoke a method with parameters through $_GET/$_POST (maybe through a LoadVars call) and your response is XML.
Example: A way of making a HTTP-Request and returning a XML document into a typecasted ActionScript XML Element
// Create the Load Vars invocation class
myVars = new LoadVars();
myVars.action = "pingback"; // My RPC method
myVars.message = "hello world"; // My method parameters
// Create the XML response
myXML = new XML; // This is our target object, which the results from sendAndLoad are loaded into
myXML.onLoad = function(success) {
trace(this); // This is where we can process the required assets
}
// Invoke the command
myVars.sendAndLoad("PingBack.php", myXML, "POST");
Flash Remoting
Flash Remoting is apparently faster and more efficient to use than this method (or webservices), and will return native objects for you to work with.
On the Adobe site they mention under their Macromedia Flash Remoting MX product (which gets replaced with full functionality for PHP with AMFPHP):
Macromedia Flash Remoting MX provides the connection between Macromedia Flash and your web application server, making it fast and easy to create Rich Internet Applications. With its powerful yet simple programming model, you can easily integrate rich Macromedia Flash content with applications built using Macromedia ColdFusion MX, Microsoft .NET, Java, and SOAP-based web services.
A simple example may be creating a database query and relaying the result to Flash. With Flash Remoting you can simply perform your SQL statement and return a record set to Flash which can then be used in many different GUI components.
AMFPHP
AMFPHP is a framework that allows you to invoke Flash Remoting to PHP without requiring the Macromedia Flash Remoting product offered by Adobe. On their website they describe AMFPHP as:
AMFPHP is an open-source Flash Remoting gateway. It’s fast, reliable, 100% free and open-source. Flash Remoting is a technology built into the Flash player core that enables sending data between the server and the client seemlessly. If you’ve built XML-based RIAs you know how much of a pain it can be to serialize the data, debug, and integrate into your application.With Flash Remoting, you can call remote methods from the Flash client and the arguments will end up in the native remote language, and will come back to Flash correctly typed, so there’s no messing with serialization at all.
You will be able to see in their documentation how quickly you can get Flash Remoting up and working and they provide good resources to tutorials online for ways to interact with Flash Remoting.
AMFPHP automatically creates the ActionScript classes that you need to interact with your Services that you make. You can also test your Flash Remoting without even requiring Flash to be installed through a very handy Service Browser which comes packaged, and you can debug your connections through another NetConnection Debugger. After reading over this package and the documentation, and having my first play with the PingBack application, I think this is a very well made/simple framework to make life easier for PHP developers and further demonstrate the capabilities of PHP for Web Application Development.






For those of you who are interested in knowing: AMFPHP works on both PHP4 and 5
Comment by Cameron Manderson — June 20, 2006 @ 3:01 pm
For those of you interested in AMFPHP checkout Sephiroth’s page http://www.sephiroth.it/amfphp.php and the AMFPHP homepage http://amfphp.sourceforge.net/.
Sephiroth is one of the founding developers of AMFPHP and he provides many helpful AMFPHP, PHP and Flash tutorials.
Comment by Richard Lee — June 21, 2006 @ 9:21 am