Installing Flash Remoting for PHP (aka amfphp)
First install the Flash remoting components. The components include the classes you need to connect to Flash remoting, and also debugging and formatting classes that will help out when developing.
Next download the current version of AMFPHP from http://www.amfphp.org/. We will try to update this tutorial as the AMFPHP project matures. For this tutorial we will be working in a Windows environments and Mac OS's (there's not much difference).
After you have downloaded the current version of AMFPHP unzip them and take a look at the files. You will see three folders: amf-core, browser and services. The most important is amf-core, where the core library resides. In the app folder, there is a file called Gateway.php. This file builds the communication between the application and the amfphp library, we need to correctly point to it in order to work with the complete services. This path is the most important consideration that we need to keep in mind when building our service. The service should have: a gateway php that points to the amf-core/app/Gateway.php and a baseclass pointer to our service.Our service could be anywhere as far as the gateway knows the path, but the usual practice is to leave in services folder inside amfphp installation or in a services folder inside our own application. Here's a minimal gateway in version 1.2 (full version with the explanation of all parameters is included in amfphp main folder):
<?php
include "../amfphp/amf-core/app/Gateway.php";
//You can set this constant appropriately to disable traces and debugging headers
//You will also have the constant available in your classes, for changing
//the mysql server info for example
define("PRODUCTION_SERVER", false);
$gateway = new Gateway();
//Set where the services classes are loaded from, *with trailing slash*
$gateway->setBaseClassPath("./services/");
//Loose mode means echo'ing or whitespace in your file won't make AMFPHP choke
$gateway->setLooseMode(true);
//Read above large note for explanation of charset handling
//The main contributor (Patrick Mineault) is French,
//so don't be afraid if he forgot to turn off iconv by default!
$gateway->setCharsetHandler("utf8_decode", "ISO-8859-1", "ISO-8859-1");
//Error types that will be rooted to the NetConnection debugger
$gateway->setErrorHandling(E_ALL ^ E_NOTICE);
if(PRODUCTION_SERVER)
{
//Disable trace actions
$gateway->disableTrace();
//Disable debugging headers
$gateway->disableDebug();
//Disable Service description
$gateway->disableServiceDescription();
}
//Service now
$gateway->service() ?>
Note that here we left the setCharsetHandler to utf8, production server to false, so we can see possible errors and also set the error level. Important is to set the path to the amf-core/app/Gateway.php correctly at the beginning and also the setBaseClassPath method should point to the services folder you're using. Note that both path are relative to the place wher gateway.php is. You can use absolute path also, but then each time you move your application you should fix the path, specially if you don't use your service inside the amfphp library like we will do.
There are many new features in the last library, just let's point a few:
- - When opening directly gateway.php in your browser, you get a message saying: "amfphp and this gateway are installed correctly". In older versions you get a download
- - The debuggateway could be used to get detailed errors (and errors that doesn't appear using normal gateway), just point to debuggateway.php instead of gateway.php. The file debuggateway is in main folder of amfphp library
- - The service browser allows to browse the services that you have put in services folder inside amfphp library. It list the method table and also generate base code to call your methods in different flavours (AS2 class, AS2 inline, ARP framework, Flashcom, etc)
For our example we need to create a folder for our application (named Hello) on the same level as the amfphp folder. So in the first line, we go a step above to look for the amfphp folder (relative to this file). Then, we need to create a services folder inside our application folder (named Hello) to store all our own services and set it as the BaseClassPath for our service. But before moving to our folder structure, let's take a quick look at amfphp installation for Mac users

5 most recent
Flash streaming servers
Tree menu
Flash Spell Checker
Flash Remoting Library
MX 2004 Chart/Poll
Articles