5

I'm looking to replace PHP with something better (everybody seems to say that PHP is evil, right ?), and considering server-side JavaScript.

node.js seems very popular, but I'm afraid I'll go crazy with asynhronous stuff. Is it possible to write normal (synchronous) code under node ?

My whishlist: web and command-line scripting, good performance (on the The Computer Language
Benchmarks Game
, V8 seems to be an order of magnitude faster than PHP), preferably developed by some company or community so that it will not be just abandoned someday, user community with a decent modules library.

I don't consider various frameworks based on Rhino, as Rhino runs in Java, and I'm not into Java, aware of it's memory footprint, and the whole idea of compiling javascript to java makes no sense to me.

Spent some time googling, and found numerous projects: Myna, Meteor, GromJS, APE, GLUEscript, v8cgi, silkjs, wakanda, GPSEE, sorrowjs, ejscript, Persevere, PhantomJS.

Does somebody have any experience with those ? Any recommendation are welcome.

igouy
  • 2,433
  • 17
  • 15
Sandman4
  • 2,555
  • 2
  • 20
  • 18
  • 1
    If you're not ready for the asynchronous model then you're right: Node.js will drive you crazy. – Pointy Jul 14 '12 at 21:43
  • @Sandman4... I can feel you on this question.. I did look for fancy new things for my simple implementations sometime back, but I dont do it anymore, unless it serves a business purpose. The challenge with fancy implementations is the maintenance in the long run. If your organization has enough PHP skills, do it in PHP.. OR simple .NET (i'm aware .NET is not simple though :D ).. OR use Node if your organization will move along that path to build competencies! – Hasith Jul 15 '12 at 01:12
  • Rhino doesn't compile to Java, it compiles to bytecode. – Dave Newton Jul 15 '12 at 02:57
  • 1
    Don't want to sound like a fanboy, but the idea of PHP being 'evil' is more a matter of trendiness. It's still the most used language for webdevelopment by far. People tend to think Microsoft is evil too, yet 90% of us at least have a douldboot or bootcamp with Windows. – JSON Mar 10 '15 at 00:36

5 Answers5

6

Well Node.JS is the way to go if you ask me. You can write synchronous code, BUT only do that in command line scripts. When writing a web servers you have to go the async route otherwise it will not perform because JavaScript is single threaded and everything comes to a halt.

The reason Node.js is so fast is because of asynchronous IO.

You will get used to callbacks and eventing and after a while you don't want to go back.

Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

Split Your Infinity
  • 4,019
  • 1
  • 18
  • 19
  • 2
    I don't think _JavaScript_ is single threaded, it's an _implementation_ which is single threaded. Only I don't know if it's a limtation of node.js or of V8 itself. – Sandman4 Jul 14 '12 at 21:54
  • Javascript is inherently parallel because it uses asynchronous calls. The problem is that it runs on an interpreter that is usually single threaded. – Andrew Rhyne Dec 07 '12 at 07:29
  • JavaScript is meant to be used as it is commonly used (surprise surprise). It has the main thread that executes interpreted JavaScript that works in a non-blocking environment and multiple workers which work on separate threads (in a blocking IO environment). It can be clearly seen in Node.js (JavaScript & C++ modules) but is actually done in all (major) browsers as well (Node.js uses V8 engine after all). With that in mind, it's up to you whether you call it single-threaded or multi-threaded. – Pijusn Apr 14 '13 at 09:40
5

Meteor. Built on top of Node.js and growing very fast.

In Meteor, your server code runs in a single thread per request, not in the asynchronous callback style typical of Node. We find the linear execution model a better fit for the typical server code in a Meteor application.

UPDATE One year later - Why Meteor

Dan Dascalescu
  • 110,650
  • 40
  • 276
  • 363
4

Have you looked at Comparison of server side JavaScript solutions ?

Node.js is popular. As for php speed, have you looked at HipHop? Rewriting your code in javascript probably won't give much of a performance boost over php.

Nikson Kanti Paul
  • 3,211
  • 1
  • 31
  • 49
bill1
  • 41
  • 1
  • I spent a whole day googling so yes, I saw the wikipedia. My idea is not a performance alone (though benchmark in the benchmark game look impressive), just want to try something else than PHP, maybe somewhat more "ordered". – Sandman4 Jul 14 '12 at 21:51
4

Nodejs is very good option on many fronts.

But you say you are concerned about its a async nature.

Two points on this.

  1. you never need to worry about async and can continue to write you application from top bottom like PHP. That's if you are not performing "blocking IO".

  2. If you are performing "blocking IO" like reading a database or accessing the file-system than you will need to deal with async. Luckly there are good ways to do this without the need to change you coding practices too much.

jamjam
  • 2,903
  • 7
  • 29
  • 39
3

Thanks for providing the list of "numerous projects" you found. We are currently using Microsoft ASP 3.0 ("Classic ASP", coming with IIS) that provides a server-side JavaScript implementation since 1996 - it's fast, mature and due to the COM technology quite extensible. If you are not fixed to open source, it's worth a look. For our open source strategy, we will have a closer look at SilkJS.

Naradana
  • 580
  • 4
  • 4