Flash / ActionScript + AMF + Zend Framework mini-How-To

There are times when you need your Flash applet to fetch data from an external source. The simplest way to do that with a PHP backend is a combination of Zend Framework’s AMF module and Flash’s built in AMF remoting feature (Action Message Format).

The steps to go about doing that is to have the client side flash component, and a server side PHP component with Zend Framework installed.
On the flash side, you create a netconnection object, assign the gateway as the URI of your web service (http://example.com/services/amf.php in this case). You specify a responder and set it to listen to any events. In the example below, I use JSON to encode the objects, but that’s optional, I just happened to be dealing with JSON objects at the time.

Source example follows:
Continue reading

Java Applet with PHP XML-RPC web service

In the past, I needed to write Java applets that interacted with a PHP backend for data fetch. One method I used was to implement XML-RPC. The XML-RPC standards. On the PHP side, Zend Framework has a pretty good XML-RPC server / client class built in. See Zend Framework XML-RPC. On the Java side you can implement the XML-RPC client as such.
Continue reading

Using Memcache with PHP

Caching is important. For web apps, it can act as the first line of defense between your web servers and the database. A simple method for caching is to store any frequently retrieved data and store it in the cache. Memcache lookups are inexpensive in comparison to MySQL. Albeit MySQL caches the results, but those results can be invalidated if the table gets updated. Below is a class that you can use as a facade infront of the memcache object. It also makes things simple as you only need to create one instance of the memcache object via the getCache method.

Continue reading