PHP as client to Node.js server - php

I want to use PHP (Symfony2) because building apps with it is quicker than building apps w node (IMO). I want the speed and scalability of node, however. My proposed solution is to use node to handle all of the app's data. I would then use Symfony2 as a client to node and pull any data I need from the node server's REST API. I could then connect to node directly with my iOS/android app and take advantage of its scalability. Is this a viable solution? How can this be improved?

What makes Symfony or any Rails inspired framework fast to develop is the scaffolding.
By using Node for the backend to handle the data management (API), you are loosing all of that, and keeping only the VC (View Controller) of Symfony's MVC. And you won't get any faster if you only keep those and add the mess of having 2 backends.
They are some Rails inpired frameworks for Node.js out there.
Railway is one of them.

If I understand you correctly you want to know.
a). If you can build a API server with nodejs. The obvious answer is yes.
b). If your PHP app can get data from the nodejs api server. Again yes you can do this.
c). If your mobile app can get data from the nodejs api server. 3rd time yes.
But understand that you now have to deal with two separate server-side technologies\langauages.
You will have to weight-up if this "quicker" or "more maintainable" then building both applications using the same stack.

Related

Azure with API for WPF and javascript

I want to create following project :
Server application hosted on Azure - it connects to databse via Entity framework and gives and API for anyone who want to connect (but with account stored in SQL database)
WPF application - it consumes server methods, objects etc.
Web app (php & javascript) - also consumes server methods and object etc.
IMPORTANT : I have only azure student's subscription and I want to hold onto it - buying anything else is out of the question unless it has strong argumentation.
I figured that to do this I have to create REST Web API because I have no other choice to connect to server than via HTTPWebRequest (because I want to have the same API for WPF nad web app).
My question is : does better solution exists?
I think I can create different API's for desktop client than web app but I have no idea how to do that. Whould you be so kindly to show me other way?
Why dont I want to have this solution?
Reason is simple. For big databases and slow internet connection it would take ages to download whole data in few seconds. As far as my knowledge goes there is no lazy loading in REST thus my WPF application's thread reponsible for downloading database would freeze for a big period of time.
If my question is too broad please leave a comment before you put up a flag.
Also, any tips regarding my project design are well appreciated.
Different APIs for Desktop and Web: this can be done easily enough. Assume you have a class library to contain your business logic (domain stuff). Create a web api project that makes use of it, then create yet another web api project separately that also makes use of the core models. When you deploy, deploy each separately to a different domain/subdomain (I'm unsure if you'll require further Azure resources for this, but consider api.desktop.myapp.com and api.web.myapp.com... no real technical reason why you can't do it that way, though for architecture reasons I'd avoid it (it's really coming close to if not definitely is duplication of code).
Same API for Desktop and Web: you stated that you thought you'd have to do this differently for the desktop and web, specifically because of the resource usage on the server. I disagree here, and think you should implement some standardized rate limiting into your API. Typically this is done by allowing only X amount of resources to be returned in a single call. If the initial request asks for more than X limit, an offset/nextID is returned by the API, and the client submits a new request noting that offset/nextID. This means you have subsequent calls from the client to get everything it needs, but gives your server a chance to handle it in smaller chunks (e.g., check for rate limits, throttling, load balancing, etc). See the leaky bucket algorithm for an implementation that I prefer, myself: https://en.wikipedia.org/wiki/Leaky_bucket)

implementing a chat webapplication

I need to develop a web application with a chat feature, and I would like to know if there are any sophisticated ways to create a realtime web-application with a push engine.
I know jQuery, and I can handle to create a chat web-application which, in the client side, check every period for new messages, and show them, but I don't like this solution and I was wondering if there are any better ways to do it.
In my research I discovered the existence Ajax Push Engine project, and it looks like what I need, but when I was navigating in their website I found it not very well done and somehow incomplete, so I was wondring if there API is stable enough to be put in a production environment if not are there any other solutions?
Sorry if I made it long, any help/hint/link/suggestion would be very welcomed :)
EDIT
I would like to specify that I'm working with PHP in the server side
Here is an implementation in NodeJs.
http://dhotson.tumblr.com/post/271733389/a-simple-chat-server-in-node-js
I recently (year 2012) developed an application in ASP.NET MVC3 where I used SignalR for real-time messaging between server and client. At their own site, they describe SignalR like this:
ASP.NET SignalR is a new library for ASP.NET developers that makes it incredibly simple to add real-time web functionality to your applications. What is "real-time web" functionality? It's the ability to have your server-side code push content to the connected clients as it happens, in real-time.
... and they give the following example of what you can use SignalR for:
SignalR can be used to add any sort of "real-time" web functionality to your ASP.NET application. While chat is often used as an example, you can do a whole lot more. Any time a user refreshes a web page to see new data, or the page implements Ajax long polling to retrieve new data, is candidate for using SignalR.
Further, based on my experience, I believe it is very simple to set up, easy to use, and have a good github page with well-written documentation that gets you going in no time. I can highly recommend it :)

Does drupal or joomla allow a combination node.js and socket.io with php?

I'm looking into the development of a site where socket use is a must for real time updates. I understand with wordpress it is difficult to incorporate node.js and socket.io and was wondering if this is the case with drupal. Specifically could I incorporate node.js and socket.io with php? What specific steps would I need to take? I appreciate the help and of course if you give me a good answer, I'll rate you up.
There are currently Node.js modules that connect to Drupal, Joomla, and WordPress. I wrote the one for Joomla: https://github.com/jlleblanc/nodejs-joomla You can find all of these through NPM. First, you would download one of these modules, then you would also download the Socket.io module. Then you would write server side code connecting the CMS to Socket.io. Finally, you would write client-side code to talk to the socket running in Node.
You can have it separated and since you want some client-server communication with node.js, you can have it - outside Drupal (this is the easiest and cleanest way).
CMS you use (be it Drupal or Wordpress) does not limit your JavaScript from using socket.io and node.js for the calls you want to be made outside the CMS server-side code. You can eg. read the same database Drupal/Wordpress does, but using Node.js and returning the results directly to the client-side JavaScript script.
You can integrate Socket.IO with whatever technology you like, but you need to think of them as 2 separate parts that need to communicate.
I see 2 solutions for Socket.IO to communicate with an external service (Drupal, Joomla, Wordpress, whatever):
1) Making a rest API for your Socket.IO application (for example using Express for the API layer and then passing messages to Socket.IO with an EventEmitter).
2) The better solution in my opinion is to use a message queue like Redis, RabbitMQ or ZeroMQ. The Drupal website would send a message down the channel to Socket.IO and then Socket.IO would send that message to the client(s).
If you are creating a system that needs authentication also, I suggest you don't let your users send message directly with Socket.IO, but make an Ajax call to your main server instead (Drupal for ex.). That way you can check the user's identity more easily. (This scenario would be a fit for a chat based system that requires authentication)
Although this video tutorial is for EventMachine with Faye, the same logic could apply to your app: http://railscasts.com/episodes/260-messaging-with-faye

php framework to serve android app

I'm developing android app. It's some sort of social network. Where user can add friend and some few stuff. I've been working on php for quite a time now. But android is totally new for me. The app will be served by a web service.
My android skill are not good. So total time I spend on working on android part is more. So I'm thinking is there any framework that can be used to serve my application. With this I can reduce time to implement web service. I know some of framework but as I have not worked with them, I don't know how much they can be extended to fit in my need. OR should I implement it by my own without any framework ?
All the suggestions, advises will be extremely helpful.
In my opinion you should definitely go with a framework, so you can concentrate more on developing the Android app.
Important is, that you choose your backend framework wisley. So it should be a lightweight and/or RAD (Rapid Application Development) framework, which enables you to use code generation for common patterns to get startet very fast.
I can recommend Ruby on Rails. If you want to stick with PHP, then my recommandation would be Symfony 2 or Kohana. Using those frameworks, you should concept and implement an API, preferably RESTful, which provides your Android application with data and can be used later on for all other kind of mobile apps or third party applications.
If you go with Symfony 2 you can have a look for the FOSRestBundle - a bundle which provides tools to create a RESTful API.
Further on, Symfony 2 comes with a very good documentation - including a getting started section, as well as a cookbook.
So,... happy coding. :)
I don't think a framework is really needed here. An efficient way to communicate between your server and Android is through the JSON data format. It's smaller than XML, but it's just as easy to use.
For example, to request the list of friends, you could send a request like this:
http://www.example.com/android.php?do=friends
And send your authentication cookies just like with the desktop site. A response would look like this:
{
"friends": [
{
"name": "John Lua",
"age": 19,
"friends_since": 32423434
},
...
]
}
In the production version, you can of course leave out the indentation and other spacing.
It is trivial to generate this output in PHP, but if you want, you can use a function like this: http://www.php.net/manual/en/function.json-encode.php
Parsing it again in Java (on Android) can be done with a library: http://json.org/java/
You would request this response with a normal web request in Java. You can find information on web requests with cookies here: http://www.hccp.org/java-net-cookie-how-to.html
Serverside, you would handle Android clients just like desktop clients, only with a different output format.

Best service/connection combo for Flex/Server Implementation

I'm starting a Flex app on a pretty big reporting engine and want to know how best to connect to a Postgres Database. I'd like to create a REST API architecture so I can use the service for more than just the Flex app(mobile possibly).
These are my options I've found:
Datatype: either XML, JSON or AMF
Flex Service: HTTPService or WebService
Server(using PHP): ZendAMF, custom json_encode implementation, Zend_Rest_Server
I've got my views all mapped out, and the api functions designed. Basically what I need is advice on which Flex / back-end service combo to provide.
Thanks for the advice!
Best service/connection combo for Flex/Server Implementation
There is no best way, but actually depends upon your project and how would you like to proceed. There are three ways.
Remoting
HTTP Service
Web Service
Since you would like to re use those services in other applications too, i would suggest you to go with Web Service. You can create your Web Service using any Server siding language which you prefer and communicate it with your Flex Application.
Regarding AMF
Its one of the ways how you can interact your Flex App with Server siding language. AMFPHP or ZendAMF does a good job and its so easy to communicate.
I would suggest you to concentrate more on Flex Architecture rather than looking into how your Flex is gonna communicate with Backend.
Check out for Modules based Architecture.
Check for which framework you are going to develop your Flex App. [ Mate, Cainogram, Swiz or someother] When you have decided with your frontend Architecture on how the flow should happen, you can then decide on how to communicate and which is the best possible approach for your project keeping the future things in your mind.
Since your Application is going to be reports oriented, go for Web Service.
[I] want to know how best to connect to a
Postgres Database.
Best is very subjective. You probably don't want to connect to the Postgres database directly from Flex. Flex is not designed for such things. I recommend using an application server as middleware. ColdFusion, .NET, PHP, Java, and just about any other 'current' application server can be used as that middleware. I would recommend using whatever you (or your team) is familiar with.
For Flex, I strongly recommend you using an AMF implementation. AMF is a binary format and will give you smaller data transfer packets, plus server side object to client side object conversion. It'll save you some time writing XML parsing routines, which can be annoying at times.
With ColdFusion, it is pretty easy to create a server side service (CFC) that can be used for AMF, SOAP Web Services, and REST services all at the same time. You just specify 'access="remote"' on the function definition. I would expect other server side languages have similar functionality, but never investigated the web service related features of other languages.

Categories