10.19.2008
Website back online. We had some issues with DNS and then had an old version of the site. I had to find a backup for the site to get it back online. The content is currently here for refrence. We are working on putting together a new site!

07.13.2008
The Essential Guide to Open Source Flash has been released. If you are just getting started with AMFPHP check out chapter 7 for a complete guide to getting started in Flash or Flex and examples from HelloWorld to Class Mapping in Flex for a CRUD application. I got my author copy this weekend and it has a ton of great content!

03.31.2008
Get ready for the new Flash Player. If you are having issues with security errors check out this blog post! crossdomain.xml fixes amfphp for april flash player release

03.10.2008
I have posted a simple Flash CS3 datagrid being populated by a mysql table on my blog. I am working in a simple CRUD example and this is the first half! Flash CS3 DataGrid with AMFPHP & MySQL

02.24.2008
The Essential Guide to Open Source Flash Development from Friends of Ed will be out this summer and feature AMFPHP as one of the topics. I have been frantically getting my examples done. There are some nuances between Flex 2 and Flex 3 that I wanted resolved before I finished my chapters but it should be some great content. Expect the majority of the information making it onto the site in snippets.

01.27.2008
I started a personal blog to try and get news and updates out faster. It is now aggrigated on MXNA so that should help. wadearnold.com/blog

01.20.2008
New release keeps the StandAlone Player from being able to access AMFPHP services.

01.16.2008
AMFPHP-Examples have been updated to include how to populate a Flash CS3 datagrid from AMFPHP.

01.06.2008
AMFPHP-Examples have been added to sourceforge. These examples are being documented under the new documentation.

01.05.2008
AMFPHP installation documentation has been updated for the upcoming 2.0 release. Get started using AMFPHP in Flash CS3 in less than 10 minutes.

12.13.2007
Adobe anounced today that they are opening the AMF specification.
Read the press release. AMFPHP is mentioned! Read the AMFPHP response.

12.12.2007
AMFPHP 2.0 beta documentation has been started on the site. I look forward to adding pages on a daily basis.

27.09.2007
A new lead for amfphp

Wade Arnold will be taking the lead of AMFPHP. Thanks Patrick Mineault for all your support over the years and good look with school!

20.12.2006
amfphp 1.9 beta includes amf3, json and xml-rpc support. Read about it here.

 

Overview

AMFPHP is a free open-source PHP implementation of the Action Message Format(AMF). AMF allows for binary serialization of Action Script (AS2, AS3) native types and objects to be sent to server side services. AMFPHP is challenged with implementing the entire AMF protocol to be an alternative to Flex Data Services (AMF3) and Flash Remoting (AMF0). AMFPHP allows thin client applications built in languages such as Flash, Flex, and AIR to communicate directly with PHP class objects on the server. PHP developers can leverage their PHP experience in server side code development by connecting to data sources such as web-services, databases, and business applications and return that data to the client. Client applications can also offload cpu intensive methods to PHP services and wait for the result set for presentation to the user. AMF allows for native data types and complex object mapping between the client and the server. Enabling ActionScript and PHP developers to not worry about type casting between the two languages. AMFPHP is a great solution for simple data requests such as a datagrid population from a database to complex RIA's that use Cairngorm, ARP, and other MVC frameworks. AMFPHP is one of the fastest client server communication protocols available to Flash Player developers because communication is serialized into this binary format, which is generally more compact than other representations, such as XML. In addition AMF3 available in ActionScript 3 also compresses the binary communication for increased performance.

Design philosophy

Amfphp was designed with a few simple goals in mind:

  • Quick installation and implementation
  • Nothing required - PHP4/PHP5 compatible, no extensions needed
  • Low footprint, lightweight, fast
  • Convention over configuration (service and class mapping)
  • Can be embedded into a framework (see CakeAmfphp, Seagull)
  • Services are "non-specific" PHP classes that are portable to anything without code change
  • Productivity tools included (service browser, code gen, profiling)
  • Batteries included - XML-RPC, JSON
  • Not a framework by itself (use your own)
  • Examples
  • Mimic the AMF specification

Examples

See the showcase section for live sites running amfphp under the hood.

* File courtesy of Aral Balkan. PHP source here. Flash source in the ARP example apps.

What does the code look like in the example?

Several remote methods are defined in this service. Focusing on the getOrderList function, we have:

<?php
class pizzaService {
    var 
$ordertable "amfphp_orders"// the orders table
    
var $pizzatable "amfphp_pizzas"// the pizzas table
    /* mysql_connect and mysql_select_db are in the constructor */
    function 
getOrderList ()
    {
        
$sql "SELECT o.order_id as orderido.order_status as status, o.order_name as name, p.pizza_id as pizzaidp.pizza_details as details, p.pizza_quantity as quantity FROM $this->ordertable o, $this->pizzatable p WHERE o.order_id = p.order_id AND o.order_status=1 ORDER BY o.order_time";
        return 
mysql_query($sql);
    }


    /* Other methods below */}
?>

The ActionScript code for getting the order list looks like the following:

import mx.remoting.*;
import mx.rpc.*;

var gatewayUrl:String = "http://amfphp.org/amfphp/gateway.php";
service = new Service(gatewayUrl, null, "pizzaService");
    
var pc:PendingCall = service.getOrderList();
pc.responder = new RelayResponder(this, "handleGetOrderList", null);

function handleGetOrderList(re:ResultEvent)
{
    var rs:RecordSet = RecordSet(re.result);
    for(var i = 0; i < rs.length; i++) {
        var item = rs.getItemAt(i);
        //item is an object with keys orderid, status, etc.
    }
}

The resource returned by MySQL query is automatically converted to the corresponding ActionScript type, mx.remoting.RecordSet. You didn't have to loop through your query, you didn't have to explode URL-encoded strings on a pipe (|) separator, you didn't have to write code to generate XML, you didn't have to use xml.firstChild.firstChild.firstChild.childNodes[i].

What if we wanted to send an argument to the remote method? Then we would simply call service.getOrderList(firstArg). firstArg could be a string, a number, an array, or an object, and we would receive the corresponding types in php. As you can see, you don't have to worry about serializing and deserializing your data, instantiating your class, or making sure the method exists before calling this, as amfphp does all of this for you. You can grab the PHP source here and the Flash source in the ARP example apps.

SourceForge.net Logo

 


© amfphp.org | Disclaimer | Conditions of use