Use Node.js or PHP with Websockets?

Asked

Viewed 453 times

5

Using Websockets for my project, at the end was an extensive project with thousands of lines of PHP code.

As soon as I finished writing everything and "finish" I am told that running Websockets with PHP is not feasible for large scale users because it is synchronous and runs everything again for each request.

I was recommended Node.js as an alternative due to the bass overhead and be asynchronous.

But at the same time I think that if the execution architecture inside the server is adequate trying to make the most of not having too many expenses the use of one language or another for the same purpose ends up getting them by them.

My doubts are specifically:

  • Is there any proportion of Node.js and PHP that shows me the how many % of it would be more efficient, or something like that?

  • Isn’t there an alternative so I don’t have to quit PHP? Even if I change the structures of my project

It’s frustrating my situation, and how projects these days can get full of users or not I get kind of do not know where to run.

  • 3

    I don’t have an answer, but consider the following: if the number of users in your project grows beyond the account, at least you’ll have the resources to redo what you have to (and you’re sure to see a lot of unforeseen things as it grows in scale). Don’t optimize prematurely, let alone based on "X technology doesn’t do Y", sometimes it may be true, but often it isn’t (without wanting to admit that its implementation was bad, developers blame the platform).

  • 1

    Instead, try to know what Websockets demand and in what sense PHP does not seem like a good choice to meet this demand, and if this is the fault of the language, the implementation, the webserver that turns from behind... And make sure you can’t get around it, without having to radically change your architecture (or maybe by learning more you’ll find you have to change the architecture, but without changing the language). Unfortunately I don’t know anything about Websockets (I’m even interested in seeing what they answer here), otherwise I could try to give some pointers, but I’m really in the dark...

  • 1

    @mgibsonbr took your information into account, edited the question adding more things and hope for news as I continue with the search.. Thank you!

  • Who said that PHP can only be synchronous ?

  • @gmsantos as I said I’m still researching, and by chance I met this reactphp a few minutes ago.. editions are accepted..

  • I came across such a Ratchet that uses React to be asynchronous websocket with PHP.. I will read more..

  • @Elaine does not see as editing the question, but rather the formulation of an answer :) .

Show 2 more comments

1 answer

3

PHP v NODE.js - The question that PHP loads everything again varies from one factor, whether PHP runs on Apache as a process, creating each request a new instance, or whether the same runs on Fastcgi, which we can limit the number of threads associated to the single process, this way the execution being asynchronous, the execution this way is usually applied in Lighttpd and Nginx, although it can be applied in Apache as well.

Using Fastcgi/PHP will get basically the same result, although Node.js is easier to create applications that use Websocket. As already has the application done, recommend to keep PHP and use Fastcgi.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.