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.
Related
So I'm about to implement stripe payments to one of our projects and I've read the documentation of their API which stands as:
The Stripe API is organized around REST. Our API is designed to have
predictable, resource-oriented URLs and to use HTTP response codes to
indicate API errors. We use built-in HTTP features, like HTTP
authentication and HTTP verbs, which can be understood by
off-the-shelf HTTP clients, and we support cross-origin resource
sharing to allow you to interact securely with our API from a
client-side web application (though you should remember that you
should never expose your secret API key in any public website's
client-side code). JSON will be returned in all responses from the
API, including errors (though if you're using API bindings, we will
convert the response to the appropriate language-specific object).
They have a good pack of ready-to-use API libraries for popular languages so you import them to your favorite language and just start using their API, including PHP, which is what we are using for this project.
Now, their API is large and they have a lot of objects. We are not actually going to use the whole set of features so my initial thought was to just wrap around their HTTP RESTFul interface around simple cURL code so I don't have to load their whole set of classes for the sake of performance.
Now, before I actually implemented my own cURL client arount their HTTP API I took a couple of minutes to look at the sources of their PHP libraries and they seem to do exactly that: wrap around cURL functions, throw errors, expose objectified responses, etc.
Then the question is: Is it worth to just use their library even when I know I'll be loading a lot of clases I won't use, or should I write my own wrapper with cURL around their REST API?
Consider that this question came to my mind sice we are using other services (TangoCard, for instance) and most of them have deprecated "native" libraries favoring the use of whatever is your favorite HTTP client library and just use the REST API.
Thanks!
Loading classes is almost a non-issue in terms of performance, especially if you are using APC. I think the time saved by using what they give you completely justifies the slight performance loss due to loading their classes.
However, if their code is well written you shouldn't load any classes you don't actually use.
Also, if they maintain their library it will be easier to receive updates as time goes on. For instance, we used to roll our own Facebook APIs that used curl and had to stop due to their high number of updates and breaking changes over time.
I would strongly recommend using the official libraries.
Stripe's official code has certainly been developed carefully and tested deeply. Especially for important things like handling payments and dealing with customers' money, I believe you should want the most stable platform possible.
The difference in performance, even without caching systems such as APC, should be totally negligible, and unless your scale is comparable to Amazon's or other big online stores, I hardly doubt you should focus your resources in optimizing that part of the code.
Additionally, using the official library makes it easy to maintain and update the code in response to changes on Stripe's side.
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).
I am working on a task where it is required to distribute live data (being fetched from some other server) to client using sockets. We user drupal as a framework and thus my choice of PHP.
1)I want to know the major factors that should be taken into consideration while developing this server.Like security,authentication,load etc and how should i approach this.Is there any blog/article that could be of help.
2)Is there a better choice than PHP for this?
3)ALSO is there any drupal module that could assist me in this.
I can think about one issue when you are talking about several servers connecting to you, you may want to conceder a nonblock mode.
Because when you are working with blocking mod, each server can connect at the time, meaning that there will be delay delivering the message.
http://il2.php.net/manual/en/function.socket-set-nonblock.php
I think java would be better choise, multi thread may help here.
from my point of view, this is something that you need to develop your self, socket programming needs a lot of attention.
Drupal is a Web CMS, it can be used as framework for advanced web features or light to medium web application that fits well in the traditional HTTP request paradigm. IMHO, distributing live data from multiple servers to client using sockets doesn't fit with the base assumption behind Drupal's design.
PHP can be used to write socket server. It used to be un-common, but it is becoming more and more available. ReactPHP is a non-blocking I/O library/framework suited for socket programing. Racthet is a websocket server in PHP using ReactPHP.
In any case, this would ne nothing like developing a web application with RoR, Drupal, Django, Symfony, etc.
If integration with a Drupal website is required, the Service module is a nice solution to provides a REST or XML-RPC API. Or course, direct access to Drupal's MySQL database is also an option but will probably require more knowledge of the used Drupal modules since you will have to replicate their behaviors and understand how they manage their data (for instance, how a particular CCK field is stored in your database).
Note: Previous version of this answer included reference to the following solutions in other languages: Twisted (Python), EventMachine (Ruby) and Node.js (JavaScript). These are all valid solutions when PHP is not required.
Previous version of the answer also referenced phpsocketdaemon, but nowadays ReactPHP is a more clean and robust solution.
Being as stubborn as it gets, I'm building my own PHP-based CMS and framework (named RAmen/FSM just for the kicks) that has been deployed multiple times for my customers. Now, I'm going to develop a support ticket application for it that I will deploy on a 'central' server for convenience of maintenance.
Now, I've looked into SOAP services and was happy until I got to WSDL generation in PHP and in itself. So, what would you suggest for me to 'securely' (as in, no https) manage this with SOAP-like simplicity on the client side ($support->newTicket), without the WSDL headaches on the server side? Or should I –gasp– stop being so stubborn and just go with a PHP library (in which case, please do recommend!)
Thank you, fellow pastafarians/spagnostic coders!
PHP has a native SOAP extension, that automates client as well as server. It is a little buggy in some places, but still better than nusoap (IMHO).
That said, I would never chose SOAP if I had any bearing on the decision. Use xml-rpc or a rest-based approach.
I have a similar question, whether to use REST or SOAP. I am using REST but that is beacuse i want a simple API like function not so much the rigid functionality associated with REST.
That being said here is a nice little library to get you started on SOAP
http://sourceforge.net/projects/nusoap/
By the sounds of it SOAP is actually what you want. you will fin it a bit easier to implement as you get the domain models from the WSDL.
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.