Is node.js a replacement for PHP?

If so, why bother with PHP? You have to use javascript anyway, right?

Have to wonder, why is there no Wordpress, or Drupal, or whatever for node.js?

From what little I have seen, node.js seems like a lot of work to just output “hello world.”

BTW: I know very little about this, if you couldn’t tell.

People are starting to bring out Node.js-based CMSes, but they are pretty limited. Node advocates are pretty clear on the point that it is useful for certain things and not all sites. There are far fewer hosts available for Node as well.

It’ll partly depend on what’s for, you have to keep in mine that generally javascript can be controlled and altered by the user so it can’t be relied upon for sanitizing any input from the user. Also if a website relies on node.js (or any other javascript library) too much and the user has javascript disabled then that site will probably be broken as far as the user is concerned and they may say to their friends that the site is broken.

Any site should be able to function perfectly well with javascript disabled, albeit it might take extra clicks to do some things

To clarify, node.js is not a client side js library, but rather a server side server that runs javascript and works regardless of whether the browser has client side javascript enabled. The same way browsers can’t “disable” php.

It sure can work out for a few applications, but not for everything. If node is this powerful as hyped, it would’ve overtaken PHP already at this moment. We dont see this coming, so clearly both node and PHP have their own uses. Node.js may be a close substitute for PHP, but not a perfect substitute that does everything better.

Node.js is not ideally for any web application. So it will not overtake PHP. But it is very efficient in handling large number of requests, I/O connections, works great with web-sockets, and comet pulling.
It is an single threaded, event driven, non-blocking language.

That means it does not block I/O connections (Ex. database queries, file read/write, net connections) like other blocking languages (Ex. PHP) does, instead it will register it as an event to the event emitter. When the connection is completed and the application finishes handling any other events, it will handle that event. This considerably improves performance, because the application does not wait for a blocked connection.

On the other hand, the disadvantage of Node.js is that if a event needs to do a lot of computing it will block the event emitter until the current event is finished, and therefore any other events will not be handled until the current event is completed.

This information is from my personal knowledge and is possible not to be 100% accurate.

To put this in a different way, Node is idea for writing apps where you need realtime communication between the browser and the server. Examples of this might be chat rooms and stock trading apps, I can imagine it would also be useful where remote control of devices is required (i.e motorized camera systems).

As others have mentioned, you can use Node to write conventional apps such as CMSs, but there’s no real advantage over more common languages such as PHP, and there are disadvantages like less hosting options, and it’s probably going to be harder to find Node developers.

I wonder if web sockets will take over in that respect. Interesting times ahead.

My understanding of it is that web sockets are part of the puzzle… they are the technology you use to make the connection between browser and server, but you still need a server that can manage realtime connections. I have seen an experimental PHP web socket library, but I was under the impression that Node.js would perform much better in this sort of scenario due to the way it works.

What sounds interesting to me is how web sockets use a new protocol that allows for two way communication, unlike http, which is what Node is stuck with. (But beyond that I have no idea about this stuff. :D)

Node can use web sockets, with the socket.io module. But I agree, interesting times for sure!

Ah, I see. Thanks for clarifying. :slight_smile:

You can use node in conjunction with PHP quite easily. Using node as a web service platform which provides business logic for a slim PHP web application would be a pretty efficient use of resources. A lot of CMS systems can get difficult to graft complex business logic to. If you keep the CMS as an easily customizable interface for non-technical users which gets it’s business logic from services provided by tools like node, You have a very modular easily modified system.

This isn’t a competition or at least it shouldn’t be between PHP and other platforms. They are all tools we can use to make great things. Thanking of it as a big context can limit your options as a developer.

Hey…I recently started working on a few Node.js applications. Coming most recently from PHP, I found the transition to Node.js to be surprisingly easy. If Node.js is found to be easy to use the surely it overtake PHP.

If anyone is interested, there’s an article on realtime PHP apps in this month’s Web & PHP Magazine which talks a little about the Node.js, PHP and web socket stuff.

Have to wonder, why is there no Wordpress, or Drupal, or whatever for node.js?

Node is newer, and has neither attracted a sufficient number of newbie-programmers nor gotten on cheap-1-dolla-no-holla web hosters yet.

If node is this powerful as hyped, it would’ve overtaken PHP already at this moment.

Plenty of languages are more powerful, easier to learn, better written and have more tools/libraries than PHP. If they’re so great and wonderful, they would have overtaken PHP already at this moment.

Or rather, PHP is popular for reasons that have nothing to do with power, easy learning, better written or having more tools/libraries. No reason for Node.js to be able to change that, though who knows, maybe in the future it will, if one-dolla-no-holla hosters start offering it by default like they do PHP now.

Node.js is not ideally for any web application. So it will not overtake PHP. But it is very efficient in handling large number of requests, I/O connections, works great with web-sockets, and comet pulling.
It is an single threaded, event driven, non-blocking language.

That means it does not block I/O connections (Ex. database queries, file read/write, net connections) like other blocking languages (Ex. PHP) does, instead it will register it as an event to the event emitter…

Most languages with any web use have the same ability, either via a framework (Python’s twisted), a module (Perl’s [url=http://search.cpan.org/~mlehmann/AnyEvent-7.04/lib/AnyEvent.pm]Any::Event), or just building from scratch any set of [url=http://en.wikipedia.org/wiki/Green_threads]green threads/greenlets/whatever event loop system floats your boat + workers with a pubsub setup (they get spawned, they do their thing, they die). I don’t know what’s going on in the PHP world but I see above me fretburner’s link to similar things. A language does not have to “be blocking” by default. It’s like saying Language X isn’t functional because people tend to write procedurally in it. If it’s got first-class functions, you can write higher-order (functional) programs in it.

Similarly, I’ve seen people presenting talks showing their Node programs going into Callback Hell, which must’ve been a limit to the V8 engine since ecmascript itself has promisses and stuff already built-in.

I think it may be more like, people who do web programming are used to the once-revolutionary-but-now-common OO style programming, and procedural programming. So those using languages like Erlang tend to be using it because they wanted to do something else in the first place, so for example while you could build a web site/app in Erlang, not many people do it. But then I think it’s a bit of a punch in a language’s stomach to say it’s not necessarily ideal for a web app. More like the particular programmer’s personal preferences and what they’re already familiar with.

I’m sure as more people get into node, for whatever reason, more things like web frameworks will be developed for it, and simply more people will be using it. Hey, it happened to PHP.

What I would like to see the results of at some point would be a comparison of a site with different versions using:

  • Node.js Only
  • Part Node.js & Part PHP
  • PHP Only

For each one with various levels of site traffic from very light to very busy. With each being tested for how secure they are various threats and attacks such as XSS and SQL Injection. Until I see such results I can’t really say whether I’ll ever give Node.js a try

To be fair that’s 99% up to the developer to make sure stuff like that doesn’t happen. Put a toddler in a Ferrari, that sort of thing.

IMO it will take quite some time for people to navigate away from PHP to node.js – PHP has such a massive ecosystem with many great products built on top of it.

Node.js is fundamentally quite different from PHP. I also think Node.js (being based on JS) is superior to PHP in most every way. There is a growing community of developers learning node.js and it’s various frameworks but I think it will be sometime before you see blogging engines (Google GHOST it looks awesome) become as popular and ubiquitous as WordPress.

Alex

Josette posted this interesting link: Async processing with PHP and GAE.