9.2 Installing AMFPHP

First, you need to download AMFPHP from http://www.amfphp.org. As with many open source projects, you can download either the most recent stable build or the absolutely latest version of the code from the project's source code repository. Unless you plan on helping out with the development of AMFPHP, it's generally best to use the stable build. The following directions assume that you are using Version 0.5.1 of AMFPHP, so be sure to check the documentation that comes with AMFPHP if you are using a more recent version.

There are a number of ways to install AMFPHP, depending on your exact requirements, but the following two approaches are the most common.

The first approach assumes you can modify the include_path variable for your PHP environment or that you know the current include_path and can copy files to that location. For more information on how to modify include_path, be sure to check out the PHP documentation and your web server's docs. (For example, for Apache, you can modify include_path with either your httpd.conf file or an .htaccess file). Once you have include_path set up to your liking, simply copy the flashservices directory included in AMFPHP to a directory specified in include_path.

The second approach doesn't require any kind of special access to your server, but you may want to have access to your domain's web root if you would like to do a single installation for your whole domain (which is recommended). To install AMFPHP this way, just upload the flashservices directory to some location under your web root and note the path to that directory.

So far, the steps have involved getting the core AMFPHP code up on your server. The next step is to set up the gateway.php file, which acts as the gateway for your projects. With AMFPHP, you can have multiple gateways set up on your server, which is handy if you want to keep the services (the actual PHP classes you write) of each project separate.

The code inside the gateway.php file is quite short; it merely includes the rest of the code for the project and specifies where your services are located. You can find a sample gateway.php file in the examples/basic/ directory. You simply modify this file to fit your setup. It can be uploaded to any directory under your server's web root.

The lines you'll need to modify in gateway.php are:

include "flashservices/app/Gateway.php";

and:

$gateway->setBaseClassPath("services/");

If you've installed the flashservices directory using the include_path approach, you won't need to modify the first line at all. Otherwise, you'll have to modify the path so that it properly reaches your flashservices directory. For example, on my server, that line looks like this:

include "/usr/local/apache/htdocs/flashservices/app/Gateway.php";

Simply change the second line to point to the path where you keep your services. The default path, services/, points to the services directory underneath where you installed the flashservices directory. Again, as an example, here's what I have on my server:

$gateway->setBaseClassPath("/usr/local/apache/htdocs/amfServices");

To summarize how to install AMFPHP:

  1. Download the AMFPHP source files from http://www.amfphp.org.

  2. Copy the flashservices directory from AMFPHP somewhere on your server. You can place it in one of the path's specified in your include_path PHP variable or somewhere under your web root.

  3. Dig down into the examples/basic directory of AMFPHP and modify the gateway.php file to reflect your setup.

  4. Upload the gateway.php file somewhere under the web root of your server.

Note that AMFPHP is completely server-based. There is no client-side installation, and there are no client-side .as library files to include when using AMFPHP, except for the NetServices.as file, which you should include whenever using Flash Remoting, regardless of the server-side technology.

Because AMFPHP returns binary data to the Flash client, rather than returning HTML, debugging your setup can be a bit difficult. If you're having trouble, you may want to temporarily add the following lines to the beginning of your gateway.php file:

ini_set( 'display_errors', false );
ini_set( 'log_errors', true );

These two lines suppress sending errors back to Flash and instead log errors to your web server's error log.

9.2.1 Configuring AMFPHP for Web Services

To use AMFPHP with web services, you need to complete a few more steps. AMFPHP works with two different PHP SOAP implementations: PEAR::SOAP (http://pear.php.net) and nuSOAP (http://dietrich.ganx4.com/nusoap). At the time of this writing, PEAR::SOAP is compatible with a larger number of web services than nuSOAP.

The PEAR::SOAP package is part of the PHP Extension and Application Repository, which provides a library of PHP code. There are a number of ways to install PEAR packages, but the easiest by far is to use the pear command line tool that ships with PHP 4.3.0 and later.

To install the PEAR::SOAP package using the pear tool, go to a command line on your server and type:

pear install SOAP

If the command displays an error and lists dependent modules, simply install the missing modules one by one. For example, if the error message says that the HTTP_Request module is missing, install it using:

pear install HTTP_Request

Once all of the dependent modules are installed, try to install SOAP again. Once SOAP installs successfully, you're done.

If you prefer to use nuSOAP instead:

  1. Download it from http://dietrich.ganx4.com/nusoap.

  2. Create a new directory underneath the flashservices directory on your server, and name it lib.

  3. Copy all of the decompressed nuSOAP files into lib.



    Part III: Advanced Flash Remoting