phppythonnode.jswebsocket

node.js or else ? some questions about websocket


I try to make a project with php, but seems realtime chat long polling is not a good solution. I decided to try websocket.

I saw many recommend for node.js. node.js, how can it save data like php doing in mysql ?

Else will python's websocket better then node.js ? why no or yes ?

sorry I am poor in English


Solution

  • Your question is super broad... I think you can easily do some google research - but let's clear this up real fast.

    1. You can use PHP with websockets (I don't recommend). Look into the Ratchet library.

    2. Node.js CAN connect to MySQL (and any other) database to store data. BUT, node.js is single threaded (this is usually a good thing), so you have to be careful about using a database and use a lot of callbacks (don't block your single thread with a slow task).

    3. Python is great too, you can look into Autobahn and there are many other tools.

    4. Ruby is my favorite. I think it's super easy to start with... but I'm biased. You can look into Rails and add Faye or Plezi (Plezi is my pet project, you can use it also without Rails).

    You can also mix languages and use Redis to sync different applications, so one application could be your websocket service and another will be used to read and write MySQL data. This is very common when using PHP or Rails with node.js (because of the single thread) and you can probably use your PHP application with any of the libraries I mentioned (such as Plezi or Faye).