Flex and remoting with PHP, which library is the best: Zend AMF, AMFPHP, WebORB for PHP, or SabreAMF?

You’ve decided to go for remoting as the way to communicate with your PHP server, and you’re wondering which of these four libraries is the best: Zend AMF, AMFPHP, WebORB for PHP, and SabreAMF?

Well, it will probably surprise you, but I don’t think one is necessarily better than another. There are some small differences, but for me none is so big that I can declare one as the winner. It depends on your specific needs, and the context of your current workflow with PHP apps. And I will explain in a minute why that is.

Performance

For me performance is one of the top criteria that I would use to choose one over another. All these libraries are written in PHP, and although I didn’t conduct an extensive test, I don’t think consider one faster than another. If you wrote a PHP module in C, to add some new API to PHP for remoting, then you could have something much faster. For example, AmFast (a remoting library for Python written in C) is up to 18x faster than PyAMF written in Python.

As the situation stands today, I don’t think we have a winner here. If someone performs a test and finds that I am wrong, please let me know!

Documentation and ease of use

Here, the alternatives are not so level. While implementing examples with each one of them, I must say AMFPHP was the easiest to use. The documentation is OK, since it has been around for some time you can find articles explaining how to use it; and it has a Services Browser, a Flex application that lets you test your PHP services. This can be very handy when you are debugging a project. There is a folder where you can drop your service and it will be automatically picked up, and a folder for your VOs. These two folders can be configured.

WebORB has good documentation too, and it comes with examples. There is also a Flex application that provides easy access to some quick start articles, a browser service, a code generator, and a way to configure the destinations. I didn’t find this code generator particularly helpful. For example, I expected to generate an ActionScript class out of the PHP model class, instead it generated a wrapper class for the remote object, and it tried to generate the ActionScript model. I say it tried to generate, because it generates a strange data model, which basically has a property for each method on your PHP remote class of Object type. It has a special folder where you have to add your services and VOs.

The next one is Zend AMF. It has decent documentation and is the newest on the market. The guy who developed it, actually is the same guy who created AMFPHP, so it must be good. However it doesn’t have a service browser, so it is harder to debug the PHP code compared to the previous two. But it has a big advantage: it is part of Zend Framework. So if you are already using Zend Framework, or you plan to use features from it, then this is the choice for you. You need to create a bootstrap file to start the AMF server, to add the services (either one by one, or by folder), and to set the correspondence between the ActionScript and PHP data model classes.

The last one is SabreAMF. The documentation is not so good and there are not so many articles, but if you know what remoting is, then you can find your way. It is little bit strange to use, as it doesn’t impose any particular structure. You have to create a boot strap file, where you configure the corresponding data model classes.  And you need to create a callback function that will do the lookup for your service classes. Actually, if you change the callback function a little bit, you can even call your defined functions, not only object’s methods.

Footprint

The smallest ones are SabreAMF and AMFPHP. These two just do remoting. Zend AMF is part of Zend Framework, an application framework for PHP (so you have a lot of functionality, and a lot of code). WebORB for PHP does remoting, plus messaging and data management. So again, there is more code in it.

Future

It seems all four libraries are maintained, although two of them have companies behind them: Zend AMF with Zend Technologies, and WebORB for PHP with Midnight Coders. The other two have one smart developer behind them. The thing is that it doesn’t really matter who is behind it, because it is really easy to switch from one framework to another one. Thus, if in the future you find that your PHP library for remoting is no longer maintained, it is not the end of the world; you can switch to another one.

Mirror, mirror on the wall, who is the most beautiful of them all?

Instead of spending too much time deciding which one to choose, just play with it or look at an example and see for yourself which one you are in tune with. If you have some special needs, for example, if you are already using Zend Framework, or using another framework, then it is even easier to choose.

As I already said, even if you eventually find that you made the wrong choice, it is not the end of the world, you can switch to another one very easily.

Happy remoting, people!

PS. If you have a favorite, do you mind posting a comment to briefly explain why you chose it? Thanks!

29 thoughts on “Flex and remoting with PHP, which library is the best: Zend AMF, AMFPHP, WebORB for PHP, or SabreAMF?

  1. How interesting….I seach for the best amf library and this topic comes up on the day it was published!

    For me its AMFPHP; much easier to get up and running, very simple to operate, service browser, lightweight. The others all seem to have some level of obfuscation that doesnt really add much value.

  2. Hi can we use Datamgt services as in LCDS and Blaze DS in any one of them ?
    If not how to use them in PHP ?

  3. @Sumit Arora

    Check WebORB for PHP. They have support for messaging and data management, thought I didn’t try.

  4. If performance is one of the top criteria, then you probably never came across the C Encoding Extension for AMFPHP which makes it “50 to 100″ times faster, according to Patrick Mineault:
    http://www.5etdemi.com/blog/archives/2007/01/amfphp-19-beta-2-ridiculously-faster/

    That extension came out two years ago, but has been obscured and buried unless you look for it.

    Wade Arnold’s goal is to get this extension built into Zend AMF (successor to AMFPHP), but seemed to indicate this hasn’t been done yet. So, that makes AMFPHP significantly faster than Zend AMF for the time being.

  5. The C Encoding Extension mentioned above is called AMFEXT and has been maintained as late as July 2008:
    http://www.teslacore.it/wiki/index.php?title=AMFEXT

    Patrick Mineault mentioned in my previous post was a major developer of AMFPHP and has a thorough benchmark showing the impressive speed gains (the link above in my previous post).

    The latest version of this extension was even included in XAMPP, and it works for me without a hiccup.

  6. @David Pesta

    Thanks a lot for the link :)

    From my point of view, it would be nice to have this extension as part of the PHP default installation. And to have some new PHP native functions/objects to work with it.

  7. Here is another very interesting find: http://flashmog.net

    100% PHP 2-way Open Socket server for Flash apps!

    A first on the internet as far as I can find after many hours of searching.

    I haven’t had the time to get this working yet, but if FlashMOG is all that it is cracked up to be, someone ought to start making a lot of noise and get people involved in this project. It looks like a very well developed site with very low feedback on their forums. A totally undiscovered gem on the internet by the looks of it.

  8. AmfPHP is a joke. I use it for 2 years no, but with my php 5.3 it breaks. Developer doesn’t seems to live anymore, and the bugs are everywhere. I had to fix a couple on my own to get it working correctly.

    Anyway, zend misses a good service browser (witch i very like like in AmfPHP) but has the cleanest implementation.

    WebOrb is nice and very good maintained. Although it didn’t worked as fast as AmfPHP. I’m sticking with Zend just because of it’s clean coding style. (and performance on a webserver isn’t really an issue anyway).

  9. @Xeress

    The same developer (Wade Arnold) who takes care of AMFPHP implemented the Zend AMF too.

  10. Patrick Mineault built most of AMFPHP, then retired from the flash world to get into neuroscience and he handed the project over to Wade Arnold. Then Wade Arnold abandoned AMFPHP in order to build Zend AMF.

  11. I recently developed a large application with AMFPHP, it is extremely easy to use however it does lack some features which the documentation says are there. After some digging through the code the features are there just disabled. This is a minor inconvencince than anything else, as for performance I didn’t get a chance to use any of the others but we didn’t have any problems with it being slow as far as I am aware. It is adequate for most development’s needs if a little messy.

  12. I have had nothing but problems with AMFPHP on large projects, especially when dealing with ByteArrays. Corrupted streams, poor char conversions that do not deal properly with 16bit chars. It performs well, but these problems are show stoppers. It is also no longer maintained as far as I can tell.

    WebOrb is bloated with too much crap and has a very steep learning curve.

    Adobe has worked with Zend to create Zend_AMF, and it works flawlessly, and its object model is beautiful. You don’t have to use the entire Zend framework, you can just grab the AMF library separately.

  13. But can you install zend-amf as easily as amf-php

    Like for example if you don’t have the knowledge to install extra php modules/packages/extensions

    amf-php can be installed just by uploading some files by ftp and it works. I wonder how it goes for zend-amf

  14. Finally, I found the article, the best one which could provide the most information about the 4 libraries. Thank u so much;)

  15. Pingback: Wordpress + Flash + Integration = ??? « Pixellovin

  16. Pingback: Polish Adobe Flex User Group » Blog Archive » Testowa konfiguracja Zend AMF w kilku krokach

  17. Pingback: Flex and PHP Architecture « PHP Mysql Script

  18. Lots of praise for AMFPHP here. I have used it for 2 years now, and yes, it’s very easy and fast (especially on windows with the C extension) however: It falls down seriously when it comes to Authentication. I have started to look the other AMF options because of this. With 2.0 you can write your own plugins, however I don’t want to home-cook my security model.

  19. Pingback: FLEX & PHP Architecture « PHP TALENT GURU

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>