Best method for Flex to PHP communication? - php

What is the best method for communication between Flex and PHP?
In the past, we used AMFPHP with AS2, and it worked great for the most part (advantage of AMFPHP is that it also has a JSON mode that can let you seamlessly use the same remote PHP with either Javascript or Actionscript frontends).
However, it seems like AMFPHP isn't realy maintained anymore. So what do people recommend to replace it? So far, what I've found is:
Zend_AMF (looks too complex for us, we're not using the Zend framework otherwise)
AMFPHP (there were some updated made to support Flex, and it seems fairly stable, but not sure on long-term support)
XML (AS3 has nice XML handling routines, but it's more of a pain on the PHP side)
WebORB (I have no experience with this)
Roll-our-own using JSON or some other data-to-text serialization system (php's serialize(), XML, etc etc)
Mostly I'm leaning towards AMFPHP, even because of the downsides, since that's what I'm used to. Any reason I should consider switching to something else?

If you want to have fast and efficient communication, I highly recommend sticking with an AMF protocol instead of a REST or JSON custom format.
ZendAMF is actually not very confusing. Watch the introduction tutorial on GotoAndLearn, it's quite simple.
And just so you know, some of the developers from AMFPHP moved to work on ZendAMF. So in a sense, ZendAMF is the continuation of AMFPHP.

ZendAMF
Good short read - http://theflashblog.com/?p=441
For me this is no brainer. The Zend framework is one of the best php frameworks out there, and now you can talk to Flash clients. Top it off with Adobe support, that's a done deal in my book.
Alternatives :
WebORB for php
http://www.themidnightcoders.com/products/weborb-for-php
AMFPHP
http://www.amfphp.com
If you read the url above, you'll probably know why this is no longer on my radar.

I can't tell you what's best (because that's probably somewhat subjective anyway), but what I can do is tell you about a recent project of mine.
Since this was a very rich web app, and data requests to the server would be frequent, I wanted to make sure the size of the requests were as small as possible. This mean choosing JSON as the format.
Next, becuase of the nature of the application and the fact that my flash/flex developers were 1000 miles away, I needed an API that was simple and stateless. This ultimately led us to HTTP + REST.
So, the communication layer of my app is a simple Zend Framework powered set of REST resources with URIs like
user/10
review/15
location/8/reviews
They all return JSON. There's a common JSON format for all errors, as well (exceptions are trapped and converted into JSON objects) so that the flash client can easily handle failure.

If you're not using a framework like Zend, regular ol AMFPHP is still great, if for no other reason than that it's simple. I think if you feel comfortable with it, why not go for it? The thing about the role of these AMF interfaces is that they really don't need to do too much, and what AMFPHP does have in class mapping, recordset parsing into ArrayCollection, great performance.... it even does well with XML, since it gets compressed. The service browser combined with Charles has covered me as well.
I haven't been able to make much sense of how the ZendAMF effort relates to the original AMFPHP. While I can dig, I'm just saying that in following the AMFPHP mailing list on Nabble, reading Wade Arnold's blog... it's just not entirely clear.

You should consider using Zend AMF. The Zend Framework is designed to be a pick and chose framework so it is completely OK to pick a single component (in this case Zend AMF) for your application.
Zend AMF is extremely easy to use. All you have to do is specify the functions/classes you want to expose and specify class mapping to your action-script classes. Everything else is pretty much transparent.

This link is a screencast showing how to use WebORB for PHP WDMF (WebORB Data Management for Flex).
http://www.themidnightcoders.com/products/weborb-for-php/developer-den/screencasts/weborb-data-management-for-flex-and-php.html

In all projects involving Flash and PHP backend, I worked with either AMFPHP or XML requests.
AMFPHP really simplifies understanting the application for future maintenance, although it ties the whole thing to that specific technology and involves some additional overhead on the server side - to create all needed classes.
As per XML, well, what you gain here are standard REST webservices and it doesn't depend on Flash (you could pull data from a desktop app as well, for example, whereas using JSON or any other technology dependent on browsers don't allow for that).
If you want 100% future "support", then I'd recommend what doesn't need any support at all: XML.

XML on PHP can be a lot simpler with SimpleXML.
I'd just use JSON as your returns for simple calls against your PHP api.

I would definitely go for WebORB. I used it with .NET in a previous job I had and it was a joy to code with. Its ease of use and its well thought management console make it very fast to learn, and its documentation is very complete; I know it's tempting to stay with AMF just because it's what you already know, but I believe it's worth to give WebORB a try.
Take a look at this screencast for Actionscript generation with PHP, it's quite fancy.
Cheers.

PHP has a pretty good serialize() function, so for a recent project I did (high scores for a game), I used Sephiroth's Serializer. It makes the serialization on Flash's side nearly as easy as it is in PHP. Serializer also deals with datatypes (unlike json/xml) like AMF.
Downside--it's not as compact as AMF, but that's nothing gzip compression can't handle.

AMF has a pretty situational advantage. If you're looking to transfer large and complex Object, by all means go with AMF. But little does people know about the overhead that AMF carries when you're transferring small objects. If you're only transferring an object with 3 properties, using AMF can triple your payload size.
On a side note, I'm a big advocate of RESTful architecture. Since JSON and AMF are both just representations, you can build a REST service that accepts both, and negotiate the actual representation with your client at runtime.

"If you want to have fast and efficient communication, I highly recommend sticking with an AMF protocol"
And if you want a fast, efficient, and generalized communication, go with json. Then your web service will be available to flash, ajax, or regular http requests.

Related

Techniques to open up PHP application to Windows Phone - SOAP/REST

I am completing a website that I have developed in object oriented PHP.
It would be great if I could open my Application up to Windows Phone (because I love look and feel of the platform).
I have explored opening my application up by making use of the PHP SoapServer class. I've also looked at REST and retrieving data for my application as JSON, but it feels like a bitty solution.
Therefore, I would like to ask for advice on the following:
Is the SoapServer class the de facto technique for opening a PHP application up so that another platform (Windows Phone) can make use of it's classes/functions? Or are there other ways that I should consider "opening" my application up?
You can do several things, but the most used are the two you mentioned: SOAP and REST. There is no de facto standard. To be clear, because we are talking API here, there is no real difference between the fact you are using PHP (much less if it is object oriented or not), apart from how easy it is to handle your selected method server side.
I'm not a big fan of SOAP myself, especially in PHP. The support is not very good, but my experience in this is mostly in consuming SOAP, not serving it. Much of the advantages you get from reading your stuff from the .wsdl are gone if you cannot auto-import them // auto-create your classes, and the default SOAP implementation is a little too fond of just saying "segmentation error" in some cases.
That being said, your 2 choices are roughly devided by
SOAP: Stricter, more of an enterprise-setting, more difnitions and maybe therefore more control / forcing of standards. On the other hand, it can be complicated to use client-side
REST: More agile, very easy to understand for users of your API. On the other hand it does tend to create less consistent API, but that is not a given: you could be very precise in your definitions and not have this problem.
Personally I would choose a REST system in this environment. You can make your REST environment serve XML just as wel ofcourse, if you don't like JSON.

What are the relative advantages of various Python/PHP web frameworks (particularly for my project)?

I'm deciding on a web framework for an upcoming project, and I'd appreciate any advice. We've decided to use jQuery for the JavaScript, and are heavily leaning toward Python or PHP (more Python) for our server-side logic. I'm especially interested in web2py because of its jQuery integration.
About our project
Our project is to develop a security console for a complex
cybersecurity system operating within an organization's internal
network.
This console will be largely server-driven, as messages come in from the network and must be pushed by the server to the user.
The user will also be able to initiate security actions, the implementation for which will likely be in C++.
The interface we've planned will be relatively rich, and I want to leverage jQuery's power as much as possible.
We have some control over the browser environment we'll be running in (e.g., we don't have to worry about clients with JavaScript disabled).
Our site is likely to have only a few, long-lived client connections.
We are looking for software components with permissive licenses, though we're using some copyleft components (I see that web2py is LGPL while Django is BSD, so +1 to Django)
We have about a month to create a functional demo of our system, of which this interface is a small (but visible) part.
About us
We are two developers with about 5 years of programming experience, but little web development experience. I have several years of Python experience and a summers' worth of experience messing around with PHP. My coworker has some Python experience and has never touched PHP.
I used Django once back in 2008, and was frustrated by the file and code structure, which I found highly unintuitive. Perhaps this structure is inherent to the MVC model (I've had similar experiences with Django and CakePHP since), and I just need to bite the bullet and memorize it.
My Question
Given the information above, what are the relative advantages of the various Python/PHP web frameworks for our project? As mentioned above, I'm especially interested in web2py because of its jQuery integration, though Django's dominance is (once again) hard to ignore.
Thank you very much for your time!
Before deciding on a framework, you should first decide if you want to commit to a language you are unfamiliar with.
You said you've both got minimal PHP experience, so you have to weigh up the advantages here; Will the pros for going PHP (if any) out weigh the amount of time the developers will need to spend to retrain?
(Although depending on your background experience, PHP should be very easy to pick up.)
If you frame it like that, PHP would have to have a pretty convincing offering to give you. From what I'm seeing, specifically Django vs web2py, they both seem very close in functionality - which is good, but doesn't provide the "you must use x!" scenario you may be after.
However, If you will be bringing more people in later and feel finding people to work with web2py will be difficult, it may tip it to PHP. You said your self, Django's popularity (and BSD license) is hard to ignore, and it should make it easier to find people for later expansion.
If it were me, in your shoes, I would go with web2py. Assuming the development team will continue to be Python focused for the foreseeable future.
Python vs PHP: Python
With python, you can always write wrappers for C code so you won't have to mess with starting other processes and passing args to them. That might be useful for your security functions.
Web2py will allow you to easily write a webservice for this too, to more easily integrate the C portions with the web-site infrastructure.
If you already prefer python, I would go with that. If you need to bring on web-developers later that are trained in PHP, teach them Python. It won't take long, and I'm sure they'll appreciate it in the long run. Plus, moving from a PHP MVC framework to web2py or even django would make things easier. I've used CodeIgniter for PHP and find that web2py was so much simpler and easy to understand.
Also as for the directory structure, django is not actually true MVC -- it's MTV (model, template, view).
I find web2py's organization a little more straight-forward. But yes, either way it can seem strange at first. I would say YES, you should bite the bullet and use MVC.
In web2py, the "view" is html markup with the ability to write raw python code. The controller extracts data from the model (database), attaches any needed files (css/js etc) and the model of course simply defines the structure of the data and allows you to access it in an OO way.
Lastly, I wouldn't tip my hat in favor of web2py just because of jQuery integration. It does use it, and a some of the built-in framework stuff (like response.flash/session.flash, the LOAD function that loads a page or data from another controller) rely on jQuery, but using it in another framework only means you have to write an include statement (e.g. ).
But, the way it allows/forces you to focus on development is what takes the cake for me.
I've been using Django as part of my work for a couple years now and truly enjoy it when I can make it work. Unfortunately, and maybe it's just me, but I end up spending hours working on configuration every time I start a new server, or try to make it work in a development IDE.
It's relatively simple to start a new project and start coding. But there are all sorts of little catches that keep things from working if you deviate from the norm. Things like if you want your django project to serve from a subdirectory like example.com/django. The information is out there to make it work. But it's hard to find.
I can't tell you if web2py has those same problems or not. I only just learned about it from your question. It does look slick and simple though. I can tell you that after the hassles of getting the applications to serve properly from whatever server configuration I'm using, django is way more fun to program with than plain php. PHP frameworks may differ.
From my understanding the project not usual web application, you must need event driven program, web server in python.
Django won't help you here.You should look into Flask, Flask has inbuilt console too.http://werkzeug.pocoo.org/, you might need to use twisted, gevent,Flask jquery.
I would recommend asking about web2py on its mailing list -- you'll get lots of help and advice there. Regarding the LGPL license, note that it only applies to the framework, not your application -- you can license your application however you like, including closed source/commercial.
It sounds like you'll need some server push functionality, but if you'll really only need a few long-lived connections at a time, you might not need to bother with solutions like Twisted or gevent. If necessary, though, web2py does include this (requires Tornado, and works using WebSockets, though can be adapted to use other methods).

SyncML with Android and PHP Web Service

I was just curious if anyone has used SyncML (Synchronization Markup Language) and if it's a good standard to use.
We'd need it for synchronising information from a tablet device to a web server (via web service) and vice versa.
Is SyncML too bloated? I was looking at some of the SyncML APIs and was quite daunting. So the big choice is to use this standard or build an in-house solution.
Even if I did do it in-house, we'd have to create some sort of way to define the data we're sending up, so definitely looking at building an XML schema, or alternatively use JSON.
Any opinions? Ideas?
SyncML and ActiveSync (and possibly some other prepared solution) have a signifficant advantage: There are some implementations that are probably stable. Another signifficant advantage is that the protocols are designed and tested. If you design your own protocol, you'll have to think about all possible situations in synchronization. So, even if your own protocol can be a bit simpler, you probably have to do more work and the result can be less stable.
You can create syncml server on php through PHPSyncMl .
Besides,The syncml client can reference android itself .
by the way, these code maybe lost in the after version.

Adobe Air and PHP

i do not fully understand how to communicate between adobe air (using flex3) and php. i do understand that many use AMFPHP and Zend AMF.
However, AMFPHP seems to be outdated and Zend AMF (from what i understand) only works with the Zend framework (something I dont use, nor like IMHO).
My Question Is:
Are there other ways of communication besides these. I know that one can use xml to do this, but is it efficient? can i use xml to INSERT INTO mysql tables?
Are there other ways?
AMFPHP might be 'old' but it is incredibly functional and does its job well. The reason it isn't updated is because it doesn't really need to be. WebORB is another option. WebORB is badass. Highly recommend you check it out.
Some other options:
XML (REST style service)
JSON Standard Javascript object notation
AMF is far and away superior to either of these solutions. It is faster, smaller transfer sizes, and you don't have to dink around with conversions on either side. The server and the client speak in native typed objects, not generic ASCII data types.
You say :
Zend AMF (from what i understand) only
works with the Zend framework
That is not true : Zend_Amf can be downloaded, and used, as a standalone package, without having to deal with the rest of Zend Framework.
See : Zend Amf Download

Flex with PHP

I'm new to Flex and done a few application with only client side programming. Now I'm trying to do the back-end stuff using PHP. Can some one explain where(which folder) to put the PHP file for the Flex file to communicate with PHP. I'm using Flexbuilder 3 IDE.
Thanks
Flex will not access your PHP script via the filesystem, you have to invoke your PHP script via a web server. The easiest solution is to use XML as in your data transport language. But you can get fancy and use something like BlazeDS
This all really depends on what you want. I would make a very different recommendation if you wanted to simply poll the server occasionally than if you wanted to have a regular interface between the two.
If you are simply polling the server, I would recommend simply using the HTTPRequest class. It will allow you to create POST and GET data and serve to communicate relatively well.
On the other hand, if you are looking to have a more complicated set of communications between the server and the SWF, your best bet is the RemoteObject class with either AMFPHP, WebOrb, or an equivalent (we use WebOrb where I work). This has the benefit of allowing you to have objects of similar name/type in both Flex and PHP, meaning that communication can be made a good deal more comprehensive.
(If you are working this way, email me cwATallen-poole.com and I can give some pointers so that you do not have insane compiler arguments for Flex).
The next option is to use the XMLSocket class, but that seems to be a bit more intense than what you are looking for.
You may want to take a look at AMFPHP too, pretty handy.
Try XAMPP.Very useful.
The new Flash Builder 4 (product formerly known as FlexBuilder) supports connecting to PHP services out of the box. The use the Zend Framework to do it, and will install the framework to your test webserver for you whenever you go to setup a data service.
Adobe video tutorials:
Part 1
Part 2
Another good, non-video tutorial

Categories