We do a lot of projects with AMF at Public, and historically we’ve used amfphp on our back end. On a current project however we are using Zend framework. The Zend_AMF module is the successor of the original amfphp project, but it is missing one really useful thing – it doesn’t have a service browser like amfphp does. I appreciate that there is fairly good reason for this, but it is a super handy tool we’ve come quite used to having available.
So what’s the problem?
If your PHP developers have to start work before your Flash developers, you may find yourself with a back end, but no front end, so how do you test everything works? Moreover, how do you develop the back end at all if you can’t send and receive requests from your AMF gateway?
I wrote a simple command line tool for testing AMF calls, so I thought I’d share it with you here:
Download the amf command line program, requires PHP 5.2 with the json extension enabled.
It’s a fairly crude tool, and cannot support class mapping, but it’s currently helping us out very nicely. If you like it, or would like to see any improvements, please post a comment.
Usage:
Download and make sure you can execute the program
> wget http://lab.publicreative.com/wp-content/uploads/2009/03/amf.tgz > tar -xvzf amf.tgz > chmod u+x amf
For each service you want to test, create a file containing three lines.
1. The URL of your AMF service gateway
2. The method you want to call, <service>.<method>
3. The arguments to post to the service as a JSON array. This may go onto multiple lines
Here’s the bundled example in example_test.txt
http://mydomain.com/my/amf/gateway
MyServiceClass.MyMethod
[
"Arguments in JSON format",
"always as an array",
{ "objects": "are also legal" }
]
To execute this test, pipe the file into the amf program as stdin, e.g.
> cat example_test.txt | ./amf
You should see the deserialized arguments you are about to post, then a hex dump of the request packet, and then hopefully the response, followed by the deserialized response data.
Hi,
I have a Windows platform and am using Wget to automatically download certain data. One site is using AMF and I see no way how to make a request. How could I make your command line application work on Windows?
thank you kindly.
your tool has helped me plenty.
[UPDATE]
You can set the AMF version of the request packet to AMF3 like so
./amf --amf=3It defaults to “0″
We received some odd results switching between these, so you should use whatever your back end is expecting, but in theory it should pick it up automatically. We found that with AMF3 the service receives a single array argument, whereas using AMF0 the PHP functions argument list was populated as expected.