I'm trying to make server side structure for my new project
project will be web application which should be pretty fast
I think that using sockets will be faster than http requests and I don't want to decrease user experience with lots of page reloads. so I'm planning to use socket.io
but I want to write core of application in PHP
so I came up with idea to use Nodejs as server and use PHP-FPM from nodejs to use php
I need your suggestion is it bad idea ? if yes then why ? and if not how can I achieve using php-fpm from nodejs ?
and if you have better idea to build this kind of structure or any other suggestions please tell me
I'm planing to use latest software in all components including php 5.4+ and maybe 5.5 will be released as stable until I finish project
thanks
I've just started using Ratchet as a PHP websockets server, and it's pretty good, very easy to code for; and wouldn't have the overhead of nodejs <--> PHP-FPM
Don't know how much it will scale up with large numbers of users though.
Related
Hello !
A bit of background, I'd want to create my first android/iOS/webapp. The idea is to create a cross platform chat using :
Ionic (and Javascript) for the app
Openshift for the node.js server part
I was going to use Firebase to store the messages, but the free plan just works for 100~ simultaneous users, which ain't a lot ... So I was thinking about creating a node.js server using MongoDB to store everything. Users and messages.
The idea is that I'd get a better server side control on the data, and it seems to be nicer to me.
But is it actually a good idea ?
I'm not sure about the fact that it's pertinent to use a node.js server for that matter, I'm pretty new to those technologies (I'm a Java/COBOL developer)
Thanks in advance !
tl;dr : is storing and processing data for an iOS/Android/Webapp chat with a node.js server is a good idea ?
I think it's a good idea, in few hours you would have a working environment. With Ionic, being web technologies, you can use any library you want, probably the easiest one to use could be socket.io, is simple to use client side and simple server side. You would have rooms and everything already to exchange messages in realtime.
There are a ton of examples for using socket.io to make a chat so should be pretty easy to find infos. ( I made one myself )
I'm currently learning NodeJS and pretty excited about it.
But here is one thing that I am unsure and need help about.
As we know that NodeJS has its own internal http web server and we can simply create using http.createServer() method.
My questions are:
Is the internal http web server that NodeJS has, meant to replace similar http web server like Apache or Nginx?
If I need to create enterprise-scale application, does NodeJS internal web service capable of doing this? Or do I need to still use Apache/Nginx?
Please help. Thank you.
Adrian
node.js does not require a web server the likes of Apache or nginx, it is its own web server.
Walmart has used node for, in their words, "end-to-end javascript"... that is certainly enterprise-scale, though they don't explicitly say they're relying on http.createServer, end-to-end javascript would eliminate Apache or nginx and I doubt they've developed some exotic solution (though socket.io is a possibility)... generally speaking if you're using node on the web, you're using the built in web server in at least some capacity.
There perhaps is some benefit to using nginx as a reverse-proxy/static file server on the front end. If I were designing my "perfect system" I'd probably do that, but I'd still be passing back requests to the built in web server in node.
You don't need to use Apache or Nginx with node.js, but in practice, its probably a good idea.
Basically, Apache would sit in front of your node.js, and relay requests to and from your node app, using something like mod_rewrite.
The node http server module is great for firing up quick applications, but if you need things like SSL, complex mod_rewrites, directory security, detailed logs etc (ie all the stuff you would need in a commercial application), you need (or at least, its easier) to use Apache or Nginx in front of node.
Ok so finally decided I was way behind in knowing some of the frameworks/platforms that are out like Angularjs, NodeJS, Knockout, Backbone etc etc. And so decided to learn NodeJS first, and have set it up on a local vm of ubuntu server.
So was wondering if NodeJS was supposed to be paired with another server software like apache,nginx, etc. And let apache/nginx just serve up the basic pages and then just let node do the data communications since their site says its "for easily building fast, scalable network applications".
Because I have seen several questions on S.O. asking how to get NodeJS to run on port 80, which implies they want to run node as a regular server or they just dont want to have to always specify a port when doing requests. And have not seen anyone comment or say that node was not meant to be used like a regular server. So was hoping to get to an answer on this.
Node.js can be used standalone, out there are good frameworks to do it like express. You can clusterize your process in the same physical machine (and the same port) really easy via its native module cluster. Also, I'm sure you can use Node.js like a reverse proxy too, but some developers prefer using other tools to do it (in my enterprise, we use Nginx with some of our node.js apps).
So, in short: You dont need Nginx or Apache at all, but you can use if you want. It's very cosy to some people use Nginx to do the load balance, or even other stuff like handle the https or server static content. It's your choice at the end.
You should play something with the native library http or https first, and then check express or another framework. You will see wich parts of Node.js you love and which do you dont feel awesome.
We have a grails application in the wild. We'd like to give users using current browsers a better experience and provide some auto-updating of pieces of the site. Looking into all the options and specifically with Grails, I'm not impressed.
I really want to use WebSockets and from the investigating I've done up to this point I believe our best option is Node.js. But obviously we can't redo our application. I like Grails.
So my idea is that we use Node.js along side Grails to basically act as a READ-ONLY proxy between the client and the data. All the Node.js application will do is pull data from the database and deliver it to the client over WebSockets.
Does that sound like a valid approach? Is this something anyone else has done?
Certainly sounds reasonable; I'd suggest using socket.io to implement your transport (it will use WebSockets if the browser supports them; otherwise it will transparently use various fallback mechanisms). You might want to use a reverse proxy like nginx to avoid any cross-origin problems, though socket.io is fairly good at avoiding them.
Node is very much about letting you use the right tool for the right part of the job, rather than being a Golden Hammer.
We aren't using websockets, but we have an Angular app that talks to the grails via REST calls, which we expose using controllers.
I've build several websites using PHP and mySQL as backend, and believe that I'm fairly familiar with both. However during research for my new website I've come across node.js and mongodb (and socket.io, since the site is gonna contain a chat).
I've decided to use node.js and mongodb to run the chat - but don't know if I should just do the entire site with those two things?
Since I'm gonna run a node server anyway should I just run another (seperate) one hosting the website? Or is that an bad idea? - is it stable?
I could do the programming in PHP and still be using mongodb - but wouldn't node be way faster?
And another question:
I've planned to use ajax to handle all the posts to the page - but since I'm allready using socket.io to the chat - should I do all my post request using that?
For the ajax I've planned to use jQuery (also for all frontend effects).
don't know if I should just do the
entire site with those two things?
If you want to learn node.js then there is nothing better than coding it.
Since I'm gonna run a node server
anyway should I just run another
(seperate) one hosting the website?
You can use existing server and run your node.js app on other free port(o). I think for learning node you don't need to have dedicated machine.
is it stable?
Even versions of node.js are stable releases, however until there is 1.0 with feature freeze there could be breaking changes to its API.
I could do the programming in PHP and
still be using mongodb - but wouldn't
node be way faster?
It most probably (and definitely) would.
I've planned to use ajax to handle all
the posts to the page - but since I'm
allready using socket.io to the chat -
should I do all my post request using
that?
I would recommend stick to MVC model and use express since you can get into lot of time consuming troubles if you would use socket.io for classic stuff. Socket.io is namely for real-time functionality and things related to that.
There are already some solid web frameworks for node.js, in particular check out Express. Here's a really good article outlining some lessons and experiences from building a node.js website:
What it’s like building a real website in Node.js
Regarding your second question, it's probably still best to use AJAX handlers and HTTP with jQuery. I'm not sure that jQuery supports callbacks over raw TCP sockets.
node.js + express + jade + stylus + jQuery is my preferred environment.
Using forever to auto restart the server I've never had any real up-time issues even when I have bugs crashing the server on a regular basis.
As for socket.io + jQuery, they do get along fine, but it's just not as natural as the express + jQuery combo. I'd stick to making ajax calls for most things.
Node.JS can still be a little wild west like, but its improving. It is a very different model from coding in php, but it is very well suited for a lot of websites. You'll probably want to do the thin server (expose a REST API and your websocket endpoints) with a fatter client using something like BackBone.js to keep interactions clean.
The big win from doing the whole thing in node is that you will not have duplication of code between php and js for dealing with the DB or any other services required by both. Node.JS is also fantastic at handling tons and tons of concurrent requests.
Good Luck