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
Related
Please excuse my distinct lack of knowledge in this field. Software development is not my forte.
I am currently about to commence work on a project of which there is a large system built using PowerBuilder with an Oracle Enterprise database to serve the data up.
I want to build a nicer interface for the system and believe it is possible to use web technologies (my background) to do so. Can anyone confirm if it is possible to use PHP with PowerBuilder or is there a way in which I can interface my build with PowerBuilder?
I don't think there is a "good" way to incorporate PB & PHP but if there is a will there is always a way.
One unusual but possible way of mixing the technologies might be to write an IIS handler with PowerBuilder.NET, or you could build the handler using Visual Studio and call a PowerBuilder .NET Assembly from the handler. I find it is easier to build the handler using Visual Studio myself because I had problems getting PB.NET to inherit from HTTPHandler or using the .NET interface. Doing this would be like re-inventing ASP.NET as it basically just processes .ASP files and kicks out HTML/Javascript/CSS,etc and you'd be writing a handler for a different file extension (say .pb or .powerbuilder) and spitting out your favorite web code based on what filename and/or arguments you used in the URL.
I made something like this not long ago just to see if I could do it and it wasn't too difficult. Eventually I'll post the code on my PB blog. I've seen another implementation of something like this using CGI which is older technology, not as good as using a handler for busy sites.
Again this probably wasn't the answer you were looking for but it is an answer. Good luck.
I need some advice on which library is the best choice when it comes to creating SOAP servers (and eventually SOAP clients) in PHP.
I know there is built-in functions for this, but is that really the best way to go about it?
Also, if you could attach some arguments as to why a certain library/method is the better, i'd be much delighted.
The only requirement i currently have (apart from the obvious client/server part) is that it can generate WSDL.
Does the WSDL version really matter at all? 1.1 or 2.0 what's the real difference/benefit of using 2.0?
I would recommend looking at the Zend_Soap class of Zend Framework.
Its fairly complete and robust and has been available in the framework long enough to have most if not all of its rough spots smoothed out. Plus its part of a framework that is being actively maintained so it will continue to support new standards and any bugs that are found will be fixed.
I use PHP's built-in SoapServer class to serve requests because it's implemented in C so it's faster than any other class implemented in PHP (Zend, nusoap).
The limitation here is that SoapServer can't generate WSDL (as of May'11) so i am using Zend SOAP Autodiscovery to generate it.
I use nuSoap: http://sourceforge.net/projects/nusoap/
My question is needed for some basic understanding of webservices and more specificly
in conjunction with php
I would like to know, if it is necessary to have a wsdl file for the creation of a webservice or is that just something that is usefull to third party's that want to access the webservice?
Also, it's generated automaticly in .net environments, but for php it's a bit more difficult.
What are my options?
The thing I am after is to create a jm2ee application on my mobile that sends data to the webservice from time to time.
I read somewhere that you have to supply the arguments when there is no wsdl file.
What is meant by that? and/or what are the implications of that?
Thanks in advance, Richard
I would like to know, if it is
neccasary to have a wsdl file for the
creation off a webservice
No, it is not necessary (at least, not in PHP) : it helps others know how to access your webservice (which methods, objects, ... should be used), but a WS can be called even if it doesn't export a WSDL
For PHP, yes, it is a bit difficult to get a WSDL (many classes don't generated them :-( ) ; still, you can generatd it with another tool (there are tools in Eclipse to write WSDL files, for example).
There was PEAR::Soap that was able to generate WSDL from PHP code (but you had to write down many lines of code to get it right) -- considering there is a class included in PHP 5 to work with SOAP, I wouldn't recommend using this one, anyway.
For more informations, you can have a look at :
SoapServer ; especially, if you look at the documentation of SoapServer::__construct, you will notice it can work both in WSDL and non-WSDL mode
Zend_Soap
If you are creating both the client and the web service, then there is no particular need to futz with SOAP, WSDL, or any of that jazz.
Just use the basics of the web: the client can use GET to fetch information, and POST to send it. You can format the data any way you like, but JSON and XML are common, well-defined approaches.
If you'd like inspiration for your API design, check out some popular examples:
Twitter API
Flickr API
all the Google APIs
all the Yahoo APIs
That's enough to get you started, but if you're curious about the design philosophy, you can read up on Representational State Transfer or REST.
WSDL file documents in a machine readable (XML) format what the methods (and args for methods) offered by a web service. You do not need a WSDL file if you know what the methods and args are - though WSDL is very good to have as a means of making the web service public interface more 'contractified', if you will.
To the best of my knowledge the PHP library does not have functions to automagically generate a WSDL file for you.
Web service support is built into php5, your best starting place is the documentation.
Some sources will use the term "webservice" as synonymous with SOAP. That is a misnomer. SOAP is a particular protocol - It is one way to create a web service. There are other technologies available. In general SOAP is the preferred standard with in Java and .net, but it is a bad fit outside of this sphere. If you have the option, I would strongly suggest that you consider either xml-rpc (Which is simpler and has better direct support on php) or a http-based service (Also called REST based).
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.
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