Phalcon php vs node.js

Iliya Garakh picture Iliya Garakh · May 20, 2013 · Viewed 11.3k times · Source

We are going to develop rest server for our application (and all logic is on client javascript). So we thought to use Phalcon php, but we also need to create realtime chat system, which is much more easy to do using node.js. This made us think about using node.js instead of phalcon

Unfortunatly, we are not good expirienced in node.js, we love phalcon for its performance and internal beauty.

The quiestion is, did anybody compare phalcon and node.js performance? May be it's better to use node.js only for long polling chat requests, but i dont like when project is connected with so different tools.

Answer

Nikolaos Dimopoulos picture Nikolaos Dimopoulos · May 21, 2013

You are trying to compare two different things IMO.

node.js has a lot of power and flexibility but so does Phalcon. If you want to create a chat application with Phalcon, then you will need to implement some sort of polling mechanism in your browser that would refresh the chat window every X seconds. Getting/Inserting the data from the database will be Phalcon's job. Javascript will be used to do the polling i.e. refresh the chat page every X seconds.

The problem with this approach is that you might be hitting your web server every X seconds from every client that has the chat application open - and thus refreshing the chat contents, even when there are no messages. This can become very intensive very quickly.

node.js has the ability to send messages to the subscribed clients instantly. Web sockets can do the same thing I believe.

Check this video out, which will give you an idea of how this can be achieved easily:

https://www.youtube.com/watch?v=lW1vsKMUaKg

The idea is to use technologies that will not burden your hardware, rather collaborate with it. Having a "subscription" notification system (such as sockets or node.js) reduces the load on your application since only the subscribed clients receive the new messages and no full refresh is needed from the chat clients.

Phalcon is great for the back end with its speed and it can be used to construct the message which in turn will be passed to the transport layer and sent to the client. Depending on how you want to implement this, there are plenty of options around and you can easily mix and match technologies :)