I've worked with PHP for many years, today I work a lot with Python, NodeJS and nginx. I have a slightly different point of view from the ones presented so far.
The Node replaces Apache and I have to choose between one and the other?
You can use the node to be the server as well, but it is not a good practice, you can integrate the node to work with other servers, including Apache.
Does Node replace php? For example when we have the connection to Mysql itself?
Node can replace PHP yes, it can connect with MySQL and other databases, just like PHP, depends on the purpose of your application and the strategy you want to adopt Node may be a more appropriate solution than PHP.
Is it possible to integrate Node with Cakephp or another framework, type Rails?
You will not be able to write a file with PHP and Javascript and process them both at the same time, but integrating them is possible, both PHP make requests to the node server and vice versa. It is also possible with Rails or Python. Today we use the company where I work a middleware server made in Python with Django integrated with distributed Node servers that do the communication part in asynchronous websocket.
If I have an application already ready and want to integrate it into Node, do I have to rewrite it?
It depends on what you want to integrate, but you probably need changes to the integration points to work with the new dependencies.
Does Node depend on Nginx? If not, is using the 2 at the same time a good way out?
It is not dependent, but nginx is a great server for working with Node, either to be part of the cache or even to work with multiple upstream nodejs, allowing load balancing on your servers.
One of the things you can do to integrate your systems is to have the nginx server giving you external access and mapping the paths that will drop into nodejs and the ones that will fall into your apache that PHP provides (if you use Apache integrated with your PHP, otherwise you can use nginx to directly access your PHP too).
So in the case of monitoring real-time COUNT
, one of the interesting applications would be a websocket server on nodejs, where its users could be connected and traffic data in real time. On the server side your PHP could warn your Node every time it did an insert or remove operation on the database so that the node would replicate the COUNT
value to its clients in real time.
All this operation is possible with PHP also, using Pushstream, but in the end it is so much more complicated, that it is worth adopting the node for such a solution. Even chat or games are cool to work with node, because his proposal is to be treated as events in micro blocks and not as files processed as blocks and sent to the client like PHP.