SitePoint Smackdown: PHP vs Node.js

By Craig Buckler

The PHP vs Node gloves are on

The web is ever-changing technology landscape. Server-side developers have a bewildering choice of long-standing heavy-weights such as Java, C, and Perl to newer, web-focused languages such as Ruby, Clojure and Go. It rarely matters what you choose, presuming your application works.

But how do those new to web development make an informed choice?

I hope not to start a holy war, but I’m pitting two development disciplines against each other:

  • PHP
    PHP was created by Rasmus Lerdorf in 1994. It is processed by an interpreter normally installed as a module in a web server such as Apache or Nginx.

    PHP code can be intermingled with HTML. That’s not necessarily best-practice, but those new to the language can produce useful code very quickly. It contributed to the language’s popularity, and PHP is now used on more than 80% of the world’s web servers. It has been helped in no small part by WordPress — a PHP Content Management System which powers a quarter of all sites.

  • Node.js
    Node.js was created by Ryan Dahl in 2009. It uses Google’s V8 JavaScript engine, which also powers client-side code in the Chrome web browser. Unusually, the platform has built-in libraries to handle web requests and responses — you don’t need a separate web server or other dependencies.

    Node.js is relatively new but has been rapidly gaining traction. It’s used by companies including Microsoft, Yahoo, LinkedIn and PayPal.

Where’s C#, Java, Ruby, Python, Perl, Erlang, C++, Go, Dart, Scala, Haskell, etc?

An article which compared every option would be long. Would you read it? Do you expect a single developer to know them all? I’ve restricted this smackdown to PHP and Node.js because:

  1. It’s a good comparison. They’re both open source, primarily aimed at web development and applicable to similar projects.
  2. PHP is a long-established language but Node.js is a young upstart receiving increased attention. Should PHP developers believe the Node.js hype? Should they consider switching?
  3. I know and love the languages. I’ve been developing with PHP and JavaScript since the late 1990s, with a few years of Node.js experience. I’ve dabbled in other technologies, but couldn’t do them justice in this review.

Besides, it wouldn’t matter how many languages I compared. Someone, somewhere, would complain that I hadn’t included their favorite!

About SitePoint Smackdowns

Developers spend many years honing their craft. Some have languages thrust upon them, but those who reach Ninja level usually make their own choice based on a host of factors. It’s subjective; you’ll promote and defend your technology decision.

That said, SitePoint Smackdowns are not “use whatever suits you, buddy” reviews. I will make recommendations based on my own experience, requirements and biases. You’ll agree with some points and disagree with others; that’s great — your comments will help others make an informed choice.

Evaluation Methodology

PHP and Node.js are compared in the following ten rounds. Each bout considers a general development challenge which could be applied to any web technology. We won’t go too deep; few people will care about the relative merits of random number generators or array sorting algorithms.

The overall winner will be the technology which wins the most rounds. Ready? Let the battle commence …

Round 1: Getting Started

How quickly can you build a “Hello World” web page? In PHP:

	echo 'Hello World!';

The code can be placed in any file which is interpreted by the PHP engine — typically, one with a .php extension. Enter the URL which maps to that file in your browser and you’re done.

Admittedly, this isn’t the whole story. The code will only run via a web server with PHP installed. (PHP has a built-in server, although it’s best to use something more robust). Most OSs provide server software such as IIS on Windows or Apache on Mac and Linux, although they need to be enabled and configured. It’s often simpler to use a pre-built set-up such as XAMPP or a virtual OS image (such as Vagrant). Even easier: upload your file to almost any web host.

By comparison, installing Node.js is a breeze. You can either download the installer or use a package manager. So let’s create our web page in hello.js:

var http = require('http');
http.createServer(function (req, res) {
	res.writeHead(200, {'Content-Type': 'text/plain'});
	res.end('Hello World!');
}).listen(3000, '');

You need to start the app from the terminal with node hello.js before you can visit in your browser. We’ve created a small web server in five lines of code and, amazing though that is, even those with strong client-side JavaScript experience would struggle to understand it.

PHP is conceptually simpler and wins this round. Those who know a few PHP statements can write something useful. It has more software dependencies, but PHP concepts are less daunting to new developers.

There’s a greater intellectual leap between knowing some JavaScript and coding Node.js apps. The development approach is different from most server-side technologies, and you need to understand fairly complex concepts such as closures and callback functions.

Round 2: Help and Support

You won’t get far without some development assistance from the official documentation and resources such as courses, forums and StackOverflow. PHP wins this round easily; it has a great manual and twenty years’ worth of Q&As. Whatever you’re doing, someone will have encountered a similar issue before.

Node.js has good documentation but is younger and there is less help available. JavaScript has been around as long as PHP, but the majority of assistance relates to in-browser development. That rarely helps.

Round 3: Language Syntax

Are statements and structures logical and easy to use?

Unlike some languages and frameworks, PHP doesn’t force you to work in a specific way and grows with you. You can start with a few multi-line programs, add functions, progress to simple PHP4-like objects and eventually code beautiful object-oriented MVC PHP5+ applications. Your code may be chaotic to start with, but it’ll work and evolve with your understanding.

PHP syntax can change between versions, but backward compatibility is generally good. Unfortunately, this has led to a problem: PHP is a mess. For example, how do you count the number of characters in a string? Is it count? str_len? strlen? mb_strlen? There are hundreds of functions and they can be inconsistently named. Try writing a few lines of code without consulting the manual.

JavaScript is comparatively concise, with a few dozen core statements. That said, the syntax attracts venom from developers because its prototypal object model seems familiar but isn’t. You’ll also find complaints about mathematical errors (0.1 + 0.2 != 0.3) and type conversion confusion ('4' + 2 == '42' and '4' - 2 == 2) — but these situations rarely cause problems, and all languages have quirks.

PHP has benefits, but I’m awarding round three to Node.js. The reasons include:

  1. JavaScript remains the world’s most misunderstood language — but, once the concepts click, it makes other languages seem cumbersome.
  2. JavaScript code is terse compared to PHP. For example, you’ll no longer need to translate to/from JSON and — thankfully — UTF-8.
  3. Full-stack developers can use JavaScript on the client and server. Your brain doesn’t need to switch modes.
  4. Understanding JavaScript makes you want to use it more. I couldn’t say the same for PHP.

Round 4: Development Tools

Both technologies have a good range of editors, IDEs, debuggers, validators and other tools. I considered calling a draw but there’s one tool which gives Node.js an edge: npm — the Node Package Manager. npm allows you to install and manage dependencies, set configuration variables, define scripts and more.

PHP’s Composer project was influenced by npm and is better in some respects. However, it’s not provided with PHP by default, has a smaller active repository and has made less of an impact within the community.

npm is partially responsible for the growth of build tools such as Grunt and Gulp which have revolutionized development. PHP developers will probably want/need to install Node.js at some point. The reverse isn’t true.

Round 5: Environments

Where can the technologies be used and deployed? Which platforms and ecosystems are supported? Web developers often need to create applications which aren’t strictly for the web, e.g. build tools, migration tools, database conversion scripts, etc.

There are ways to use PHP for desktop and command-line app development. You won’t use them. At heart, PHP is a server-side development technology. It’s good at that job but is rarely stretched beyond those boundaries.

A few years ago, JavaScript would have been considered more restrictive. There were a few fringe technologies but its main place was in the browser. Node.js has changed that perception and there has been an explosion of JavaScript projects. You can use JavaScript everywhere — in the browser, on the server, terminal, desktop and even embedded systems. Node.js has made JavaScript ubiquitous.

Round 6: Integration

Development technologies are restricted unless they can integrate with databases and drivers. PHP is strong in this area. It’s been around for many years and its extensions system allow direct communication with a host of popular and obscure APIs.

Node.js is catching up fast, but you may struggle to find mature integration components for older, less-popular technologies.

Round 7: Hosting and Deployment

How easy is deploying your shiny new app to a live web server? It’s another clear win for PHP. Contact a random selection of web hosting companies and you’ll discover the majority offer PHP support. You’ll probably get MySQL thrown in for a bargain price. PHP is considerably easier to sandbox and more risky extensions can be disabled.

Node.js is a different beast and server-side apps run permanently. You’ll need a real/virtual/cloud or specialist server environment, ideally with root SSH access. That’s a step too far for some hosts, especially on shared hosting where you could bring down the whole system.

Node.js hosting will become simpler, but I doubt it’ll ever match the ease of FTP’ing a few PHP files.

Round 8: Performance

PHP is no slouch and there are projects and options which make it faster. Even the most demanding PHP developer rarely worries about speed but Node.js performance is generally better. Of course, performance is largely a consequence of the experience and care taken by the development team but Node.js has several advantages…

Fewer Dependencies

All requests to a PHP application must be routed via a web server which starts the PHP interpreter which runs the code. Node.js doesn’t need so many dependencies and, while you’ll almost certainly use a server framework such as Express, it’s lightweight and forms part of your application.

A Smaller, Faster Interpreter

Node.js is smaller and nimbler than the PHP interpreter. It’s less encumbered by legacy language support and Google has made a huge investment in V8 performance.

Applications are Permanently On

PHP follows the typical client-server model. Every page request initiates your application; you load configuration parameters, connect to a database, fetch information and render HTML. A Node.js app runs permanently and it need only initialize once. For example, you could create a single database connection object which is reused by everyone during every request. Admittedly, there are ways to implement this type of behavior in PHP using systems such as Memcached but it’s not a standard feature of the language.

An Event-driven, Non-Blocking I/O

PHP and most other server-side languages use an obvious blocking execution model. When you issue a command such as fetching information from a database, that command will complete execution before progressing to the next statement. Node.js doesn’t (normally) wait. Instead, you provide a callback function which is executed once the action is complete, e.g.

// fetch records from a NoSQL database

// process database information
function process(err, recs) {
	if (!err) {
		console.log(recs.length + ' records returned');

In this example, the console will output ‘finished’ before ‘N records returned’ because the process function is called when all the data has been retrieved. In other words, the interpreter is freed to do other work while other processes are busy.

Note that situations are complex and there are caveats:

  • Node.js/JavaScript runs on a single thread while most web servers are multi-threaded and handle requests concurrently.
  • Long-running JavaScript processes for one user prevent code running for all other users unless you split tasks or use Web Workers.
  • Benchmarking is subjective and flawed; you’ll find examples where Node.js beats PHP and counter examples where PHP beats Node.js. Developers are adept at proving whatever they believe!
  • Writing asynchronous event-driven code is complex and incurs its own challenges.

I can only go from experience: my Node.js applications are noticeably faster than PHP equivalents. Yours may not be but you’ll never know until you try.

Round 9: Programmer Passion

This may be stretching the “general web development challenge” objective but it’s important. It doesn’t matter whether a technology is good or bad if you dread writing code every day.

It’s a little difficult to make comparisons but relatively few PHP developers are passionate about the language. When was the last time you read a PHP article or saw a presentation which captivated the audience? Perhaps everything has been said? Perhaps there’s less exposure? Perhaps I’m not looking in the right places? There are some nice features arriving in PHP7 but the technology has been treading water for a few years. That said, few PHP developers berate the language.

JavaScript splits the community. There are those who love it and those who hate it; few developers sit on the fence. However, response to Node.js has been largely positive and the technology is riding the crest of a wave. This is partly because it’s new and the praise may not last but, for now, Node.js wins this round.

Round 10: The Future

It doesn’t particularly matter which server-side language you use; it will continue to work even if the project is abandoned (yay ColdFusion!) Usage has possibly plateaued but many continue to use PHP. It’s a safe bet and support looks assured for another twenty years.

The ascent of Node.js has been rapid. It offers a modern development approach, uses the same syntax as client-side development and supports revolutionary HTML5 features such as web sockets and server-sent events. There has been some confusion regarding forks of the language but usage continues to grow at an exponential rate.

Node.js will inevitably eat into PHP’s market share but I doubt it will overtake. Both technologies have a bright future. I declare this round a draw.

The Overall Winner

The final score: five rounds to Node.js, four to PHP and one draw. The result was closer than I expected and could have gone either way.

Node.js has a steep learning curve and isn’t ideal for novice developers but it wins this smackdown. Just. If you’re a competent JavaScript programmer who loves the language, Node.js doesn’t disappoint. It feels fresher and offers a liberating web development experience — you won’t miss PHP.

But don’t discount it. PHP is alive and there’s little reason to jump on the Node.js bandwagon because it looks faster, newer or trendier. PHP is easier to learn yet supports proficient professional programming techniques. Assistance is everywhere and deployment is simple. Even die-hard Node.js developers should consider PHP for simpler websites and apps.

My advice: assess the options and and pick a language based on your requirements. That’s far more practical than relying on ‘vs’ articles like this!

Do you agree with Craig’s conclusion? Was the comparison fair? Were the rounds rigged? Don’t get angry — get writing …

You might also be interested in our Right of Reply response to this article by SitePoint’s PHP and JS editors!

  • http://keithancajas.me Keith Ancajas

    1. PHP
    2. PHP
    3. PHP
    4. Node
    5. Node
    6. PHP
    7. PHP
    8. Who Cares.. – Draw! OK Fine.. Node!
    9. Subjective – Draw!
    10. PHP

    PHP Wins!

    • Florian Girardey

      Who cares about performance ? Your customers probably ^^

      • http://keithancajas.me Keith Ancajas

        That’s assuming PHP is that sluggish at all. If there’s any improve performance to be gained by using node.js i’m guessing it’s gonna be miniscule at best (assuming it’s even faster than PHP at all). For most of us, that’s hardly enough incentive to switch from a tried and true server-side language. I’m no hardcore fan of PHP and will readily embrace node.js or any other that becomes a frontrunner. I’m sure node.js will get a major traction specially from new devs as who would want to learn a 2nd language when you can just stick with one. Right now though, PHP wins for me. ^^

        • Craig Buckler

          Try it. There have been various benchmarks proving and disproving speed but, in my experience, Node.js is noticeably faster. It’s not always PHP’s fault – the web server can be a bottleneck – but the difference is not minuscule.

          • More Spinach

            Please point to some benchmarks? PHP run with APC with varnish/Nginx can host pretty much any traffic. Even WP sites have figured out the caching plugins. A more apples to apples comparison would be node vs php set up in an ember or angular environment, so it was about async calls. A properly architected app (which is not rocket science) will have php performing as well as node if not better and be much more pragmatic in many hosting environments.

          • Craig Buckler

            You really don’t need me to point to benchmarks when a simple Google will provide more than you could ever need. Most fall into one of two camps:

            1. Node.js is significantly faster than PHP, or
            2. That Node.js / PHP test was unfair because of X, but if you remove factor Y and add factor Z, PHP is just as fast.

            What’s most revealing is that few claim PHP is faster and, to make it match Node, you need to jump though various software installation and configuration hoops.

          • More Spinach

            Execution speed is up to the development/infra choices. Both allow the same speed if the overall tech stack choices are thought through. Basically, neither is better or worse. A slipper or sandal, which should I pick? Hmm. Both would be ok.

          • More Spinach

            Btw, most Google-enabled benchmarks have more insightful comments than the article itself. As the more evolved developers will point out, as in this one -by some @Frankel0: “We tend to go with NodeJS scripting when parallelization is of importance and go with PHP/HHVM for ease of use and we actually like PHP.” — http://disq.us/8nxrlh

  • Patrick Catanzariti

    I think the difficulty with something like this is that each “Round” can have different weightings for different developers. For me, Node.js wins because I’m a JavaScript developer and because a large amount of the IoT and new tech stuff I do is enabled by Node and npm. Whilst for others who are building static websites, I’d say PHP is potentially the better option?

    Either way – great, indepth article Craig! :D

    • Craig Buckler

      Thanks Patrick.

      Of course, much of it’s subjective and an extra round could have gone PHP’s way. Both are good but, for the moment, Node.js feels fresher and more flexible. Whether it’ll last 20 years like PHP is another matter…

      • Patrick Catanzariti

        Funnily enough, I can see there being yet another jump to a new language within 20 years ;)

    • Dasith

      Node is used for more control over simplicity , while php provides the reverse , node has the least amount of inbuilt libraries that do implicit thinks that it thinks the developer ‘wants’ , while php / iis/asp.net / jsp etc has a lot of inbuilt baggage which is one reason which i don’t use them for some projects and choose node over them , specifically for anything that goes on a lower level

    • RLid

      “others who are building static websites, I’d say PHP is potentially the better option”

      Static websites? For PHP? Really? Yeah, “don’t feed the troll”, they say…

    • Tomb Raider

      “Whilst for others who are building static websites, I’d say PHP is potentially the better option?”

      That seemed like a super-biased comment.

      Don’t you build static websites with HTML only? Why use a language if you want to build static websites?

      • Patrick Catanzariti

        Firstly, I’ve gotta say thank you to Tomb Raider for mentioning me otherwise I wouldn’t have noticed the trolling accusation placed upon me here three months ago! Yikes. That stings.

        I’ll clarify my terminology here. I’m not speaking of “static” in terms of the typical HTML “static” website. I’m all for HTML-only static sites and still build them when they’re best for the situation. If that was read as a dig at PHP, that wasn’t my intention in the slightest. I’d say “static website” is the wrong terminology and I’ll retract that poorly worded statement which made sense in my mind at the time. I mean “static” as in a CMS driven site of relatively static content. Having a full stack in JS can be quite handy for dynamic web applications, whilst PHP is great with web apps that excel at the typical client/server model.

        Am I saying you can’t build complicated web applications in PHP? Of course not. There’s plenty of evidence to the contrary ;) I’m just saying from what I’ve heard and seen, often Node is bringing great benefits in web apps which need massive scale in uses which don’t match the typical client-server model as well (e.g. PayPal). It could be just the latest fad, but I’m seeing a shift towards using Node for web apps over other languages (not just PHP).

        I was also speaking from the perspective of emerging tech where Node and npm enable a lot more web connectivity in the IoT and similar devices. For bridging the gap between traditional websites and emerging technology out there, Node seems to be better suited and seems to be keeping up a lot more with developments in those areas.

        I can’t say I’m that biased either way. I’m only speaking from experience and from what I’ve heard from other developers’ experiences. I build plenty of sites with PHP too and learnt PHP before really delving that much into JavaScript back in the day!

        Also, to refer to the static website question in particular – When it comes to the typical static HTML website, I often still consider using PHP just to add a small amount of templating to it (e.g. including a common menu across the site with a basic “current page” identifier) without needing to go to the level of a whole CMS.

        In the end, PHP and Node.js are both awesome. No question. Everyone will have their preferred methods for doing different styles of project and your usage may vary. That’s the joy of development. We get to build and improve with everything we do and with all the shared experience of the development community. If you are better at building web apps in PHP that scale and perform well for the load they’ll be given – do that. If you’ve got techniques or experience in doing it better with Node for your given use cases – do that.

  • http://jiffdesign.de/ sascha fuchs

    Comparing a Language (PHP) with an Environment (Node) is not really helpful. Compare JS with PHP it will end in “PHP is only on the Server Side and JS is on the Server and the Client Side – Point for JS”.

    PHP is not a bad language, the most Projects out there use PHP. Facebook use also PHP. A language can only so good as the Developer behind. Decide what you use can depend on the customers, when only a Infrastructure for PHP is available you can’t use Node. But you can use PHP (Server Side) and JS (Client Side).

    Personally i have more fun with learning Node as with PHP (in the 90s), it feels a little bit fresher.

  • gggeek

    Hey, your hello world example code is suboptimal. In php, hello world is:

    hello world


    • Yoni L.

      in your case it’s not PHP, without any open / close tag the php interpreter is not used so it’s only static txt served by apache/nginx included in an html body by your browser…

      • gggeek

        Technically, you are wrong.
        It is still parsed by the php interpreter, as long you save it in a file with a php extension.
        You might even run it via php on the command line, no web-server or browser involved.

        • Daniel Khan

          No … technically you are wrong.
          It is *not* _parsed_ by any interpreter because there is no starting tag.
          echo “hello world”; will not output “hello world” but the whole the whole echo … – so definitely no interpreter involved. Just try it out.

          • ElDerecho

            No, he’s right. All .php files are parsed by the PHP interpreter because PHP has to open them to find start/end tags to know if there’s code to run.

          • Daniel Khan

            Look at what the OP wrote. And the literal

            hello world

            is no php code and will also not be parsed by php. php looks for the starting (by the way …) tag and will ignore the rest. There is no tokenizing, parsing, lexing, interpreting going on.

            If I follow your argumentation I could create a ‘word file’ by writing ‘hello world’ into a docx file or create a json code example by writing ‘foobar’ into a text file and name it ‘foobar.json’.

            This is bogus and makes no sense, as this whole discussion by the way.

          • gggeek

            My excuses to the author for introducing a silly and OT thread. It was supposed to be tongue-in-cheek (missed the emoticon?).

            Having said that, my CS skills are quite rusty. I’m not sure if scanning the file for the php opening tag can be considered part of tokenizing or not, and if a tokenizer can be generally be considered a parser.
            But the php interpreter will definitely *scan* a php file based on its extension, not contents (assuming standard webserver configuration). And running “php -l” on my example will tell you that there are no errors in the file.

            As for json, iirc, the formal definition of what a ‘json document’ was removed from the spec. It used to be that a document needed to start with an encoding object, but that is not the case any more. Currently “hello world” is a valid document. Would it be an interesting code example? Well, yes! At least for the very reason that php used to think that was invalid input for json_decode() and later changed its mind, thus breaking its own API.

          • Yoni L.

            gggeek is right, apache leave the php interpreter what to do with .php file (defined in conf directive) but without tag it’s not PHP in fact. :) arrgh, i was just following the joke. :P

          • ElDerecho

            I think you need to read what was written… ” as long you save it in a file with a php extension.”. So yes, the PHP interpreter reads the file.

          • Daniel Khan

            Well … a string literal is no example for php code. It is an example for a string literal. If a coding example does not contain any language construct of the given language it is no code example for this given language.

          • David

            PHP will tokenize it and essentially convert it to <?php echo 'hello world'
            It's what allows PHP to be a templating language.

          • David

            ugh. Stupid discuss stripped out the code.
            it converts it to echo ‘hello world’;
            It’s what allows PHP to be used as a templating language. Any part outside of php tags get compiled into echo statements.

          • Daniel Khan

            No … it interprets everything _inside_ php tags as php. Just try to write
            Hello $foo and see what it does.

            It is further no echo in single quotes because then php code within such a block would be a nested echo what doesn’t work either.

          • JamesDiGioia

            This argument is pedantic as hell. It’s a joke you guys.

    • http://saadel.me Saad El Hajjaji

      And in Node.js:
      console.log(‘hello world’)

      • Tomb Raider

        Nope that would be Javascript. In Node.js we first have to write webserver codes.

        • nony bright

          and hello world would also be HTML or just plain text and not PHP

        • angelxmoreno

          What on earth are you saying? NodeJS !== Programming Language. You are writing Javascript 100% of the time that you run your code in Node.

          • Tomb Raider

            When did I say that Node.js is a programming language?

          • angelxmoreno

            gggeek said: “…in Node.js: console.log(‘hello world’)”
            you said: “Nope that would be Javascript.” It implies that you are not writing javascript on the backend but instead writing “nodejs”. At Least, that is how I understood your rebuttal.

          • Tomb Raider

            No, what I meant was: When you’re programming for NodeJS, you have write web-server codes, only after that you can send anything to browser. If you do console.log(‘Hello, world!’), it will not make any sense because console.log() will print on console not browser. :)

          • angelxmoreno

            When comparing NodeJS to PHP specifically for web you make a very valid point.

          • erye

            no you do not have to create a web server to use node. I don’t know where you’re getting this from. There are plenty of modules that do not require a web server. Its just javascript.

          • Tomb Raider

            Can you give me an example with a snippet? And besides, we are here comparing NodeJS with PHP so anything outside web server is out of context.

  • Rafael

    PHP is a bad language overall and is so popular because is easy to deploy (this isn’t good for larger companies).

    Maybe the zillions of smaller companies made PHP relevant, but bigger companies always choose a better language.

    • Craig Buckler

      There are languages everyone whines about and there are languages no one uses. PHP isn’t perfect but what is? Besides, bigger companies often choose Java or .NET because of the support options – not because they’re fundamentally better.

      • http://glend.me Glend Gjermeni

        Yes!! Many overlook the support of Microsoft and Oracle which is the main reason bigger companies choose them instead of the language itself.

        • More Spinach

          I work for one of these bigger companies. The quality of support from the likes of MS and Oracle is pretty much at the same level as the quality of their software.

          • angelxmoreno

            I have the same experience. My investigations on this over the years has led to simply adding “Oracle” or “Microsoft” to the conversation when discussing the software, not the quality of support, size of the application or a “better language”.

    • http://glend.me Glend Gjermeni

      There are top 10 websites which use PHP which are some of the biggest in the world, your argument is invalid.

    • https://www.phpcontext.com/wordpress Mike Mx

      Facebook is using PHP. Thank you. Language itself is not bad, it’s just so popular lots of not-experienced-so-called-programmers use it so bad.

    • David

      Really? Facebook is a small company?

    • More Spinach

      A knife is a simple tool. It can be used badly by people. It can also be used by a master chef to create fabulous stuff. A tool is a tool. How you use it is up to you. Get over this dated, lame argument.

    • angelxmoreno

      I disagree. I am Java and PHP developer and it is my experience that this is simply not true, just an opinion based on not knowing how to do PHP software properly.

  • Igor Escobar

    You’re obviously too deep in love to do a decent article about this topic. I lost interest in the very first round.

    • Craig Buckler

      What would you have liked covered? Did you disagree with my opinion? Great! Please add your comments!

    • angelxmoreno

      How about providing valuable feedback other than “it’s a bad article”.

  • http://www.simonholmes.com/ Simon Holmes

    Under – Round 7: Hosting and Deployment

    Deployment doesn’t get much easier than `git push heroku master`

    So if you’re looking at applications rather than just a few simple PHP pages, having version control built-in to your deployment method is a real bonus. Admittedly – above the free tier – it’s more expensive than the really cheap shared hosts, but thought it worth highlighting.

    • Craig Buckler

      Yes, that is easy … but how long did it take you to set it up?!

      • http://www.simonholmes.com/ Simon Holmes

        No longer than it takes to set up an FTP account. It’s *really* not difficult!

        And what’s more important: the initial setup or the ongoing repeated tasks?

        • Craig Buckler

          There’s nothing stopping you doing a similar set-up for PHP?

          • http://www.simonholmes.com/ Simon Holmes

            So let’s call it a draw. Deployment of both is easy!

          • angelxmoreno

            I agree. deployment is more DevOps than language based.

    • ElDerecho

      Using git is hardly unique to node.js.

      • http://www.simonholmes.com/ Simon Holmes

        No, no it’s not. The point is that deploying with Git is very common with Node, and is very easy. It’s the entry point for Node deployment, like FTP often is for PHP.

        Most PaaS providers go out of their way to make deploying Node very easy (normally with Git). They are addressing the issue that it did used to be complicated to deploy Node apps, normally involving managing your own servers. This is no longer the case.

        • ElDerecho

          Deploying with Git is very common with PHP too. ‘git push’ is ‘git push’ regardless of what its sending up. Though for both PHP and node apps – all apps really, I prefer to pull to the live server.

          • http://www.simonholmes.com/ Simon Holmes

            So we’re in agreement right? Git is a great deployment tool, and at a basic level quite easy.

            Agree on the Git pull, I do that with apps hosted on a VPS. For PaaS it’s Git push as you don’t remote into a server.

          • More Spinach

            PHP wins hands down in practical real world hosting. Many commenters have made the point. Node is sweet and one gets used to its quirks, but it’s a pain to set up in the real world unless you keep buying dozens of AWS or DO servers all over the place. Let it go. PHP rocks in this space, more than Python or RoR etc.

        • http://glend.me Glend Gjermeni

          Deploying with git is common with PHP, RoR, Django, not less than Node.js! But note that you can run PHP even in the shittiest hostings ever made by mankind.

  • Ashley Roux

    In regards to people complaining about performance being inacurate or of minimal difference, I can say as some one who has written performance intensive tasks (calculations, parsing, conversion, etc.) that nodejs COMPLETELY outperforms PHP by a factor of 3 in most cases.

    • Craig Buckler

      That’s been my experience. It’s not necessarily that PHP is slow, but it sits on a big stack of software which drags benchmarks down.

    • RLid

      People who write performance intensive tasks should use neither PHP or NodeJS in the first place.

      Also, Scala, Go, Elixir, (and others) are much more performant than JavaScript.

      I also think that for most web development requirements, bare language performance is rarely an issue (otherwise pick a compiled language). What matters is learning curve, team work, debugging possibilities, maintainability, etc.

      It makes me smile when people pi** on PHP. PHP is clearly not the most performant language ever (do not forget opcache btw and Zephyr in the rare cases where it should be needed), but it is easy to learn, well established (widely used, well documented, and mature), and quite nice to write and read.

      That being said, I’m moving from PHP/JS to Scala for several reasons: type safety (which I admit JS offers through TypeScript, and PHP through strict/weak typing in PHP 7 later this year), FP/OOP cohabitation, scalability, and every other benefit brought from compiled languages (compile-time cheks, code refactoring, …)

  • Franz

    this article is not quantitative or qualitative written in terms which language performs better. would it be nice if you create a fake scenario about building a specific feature for a site or app. then for this starting point, explaining which language performs better in many aspects, from setting up to deployment, and creating a fictional scenario, how node js or PHP can perform better with for example 100 k. visitors.

    This article aims to beginners in programming, but it gives false positives about which language is better.

    node or php can or could perform better, depending the project or app, we would like to test.

    • Craig Buckler

      That’s absolutely right. But would creating a single fictional scenario help? Which ever technology won, it wouldn’t necessarily apply to another fictional/real scenario.

      • More Spinach

        Yes it would. That’s the only sensible way of comparing two markedly diffeent things from different eras. While you promised you won’t leave this as “..oh pick what works for you”, at the end that’s pretty much exactly what you ended up doing. It’s hard to write a public article and not alienate one large community, I understand that, but take a real world scenario, a simple one, like building a simple weather reporting app or a to-do list or something, and show how one goes from 0 to 100%. Node.js has a steep curve and can be pretty, etc, but PHP is a very mature language that’s easy to use along with asyn JS like Ember or Angular, but also with many other things — without the muss and fuss of setting up server side environments. Even with NPM, node’s quirks are bottlenecks in the real world of hosting etc.

        • Craig Buckler

          Using a single scenario would result in a best-fit for that situation. A slightly different scenario could prefer the other option. There are an infinite number of scenarios and approaches. Even then, developers are adept at ‘proving’ a certain technology is best because much of it is subjective.

          While the rounds above could be considered general — or even vague — they apply to every project regardless of the fine details.

  • https://github.com/Pompeu/ Itacir Pompeu

    Slin(php) vs Restify(node) https://www.youtube.com/watch?v=LazgFwny67g&feature=youtu.be
    see how php is very fast,

  • ElDerecho

    A huge difference between the two that must be highlighted is that a node.js app is the server. So while that’s wonderful if you have a single app bound to port 80, if you have multiple apps running on a server, such as a CMS, forum software, and mailing list manager, you would need to set up a proxy for node.js to handle them.

    My preferred node/php strategy is to have PHP handle the front facing HTML, and use node for JSON based web services running on an alternate port.

    • Craig Buckler

      I’m not convinced it’s a “huge difference”. PHP permits multiple apps because they all pass through the same web server. Besides, spinning up cloud-based virtual servers is cheap and easy – there’s no reason you couldn’t have a server per app with their own specific set-ups.

      • ElDerecho

        If the fact that they have two completely different approaches to how they serve up content isn’t a ‘huge’ difference between them, I don’t know what would be considered a ‘huge’ difference.

        • Craig Buckler

          Both technologies require a web server to run multiple apps on the same machine. It’s just that PHP requires a web server for a single app too.

    • angelxmoreno

      One never binds their NodeJS app to port 80. At least, that is not the proper way nor the industry standard.

  • http://www.zacksdomain.com/ Zack Wallace

    I would have liked to see a compare of what types of projects are better suited for each. I tend to think of PHP as better for “websites” while JS may pull ahead for web “apps” or websites that require a lot of real time interaction and event-based features.

    Whenever I create a project, after a while it either becomes heavy in PHP or heavy in Javascript. If the project is leaning toward heavy JS, I would tend to think using a JS server would be beneficial and just get rid of the little PHP needed. On the flip side, when the project is heavily using PHP, the JS is minimal, used for some Jquery or random UI libraries.

    The point is, are the vast majority of projects both suited to either PHP or JS? Or is one really better for some tasks than the other?

    • Craig Buckler

      There are a few situations where one is a more logical choice, e.g. Web Sockets for real-time apps on Node.js. But, overall, you can do most projects in either.

  • Colin O’Dell

    Round 4 contains a couple errors:

    1. npm is not included with Node by default (on Ubuntu, at least)
    2. Composer (along with PSR-0) was arguably the biggest impact to the PHP community in recent years and is directly responsible for the PHP 5.3 era renaissance.

    • Craig Buckler

      1. npm was provided with my installation of Node on Ubuntu? How did you install it?

      2. I didn’t say Composer wasn’t good or successful but try finding a Node.js application which doesn’t use npm. Now find a PHP application which uses Composer.

      Last time I looked, npm had 164,000 packages – Composer had 64,000. Node and npm are intertwined. Composer is an option for PHP and I’d guess it’s mainly used by the top professionals – not everyone.

      Sorry, but npm wins in almost every way you look at it.

      • angelxmoreno

        this is not necessarily true. Node development and NPM started around the same time and you never learn Node without touching on the power of NPM. PHP, however, has been around much longer than Composer. The truth is your average PHP developer just does not use Composer enough. The main difference is the community. I can not develop apps without NPM or Composer and I think it silly to do so without them.

  • brutnus

    No framework comparison? No scope comparison? Round 3 he defends all the problems of JS and then gives JS the round and not a tie? Round 9 in general? Doesn’t mention PHP 7, that rivals HHVM in speed out of the box.

    • Craig Buckler

      You seriously want a framework comparison? There are dozens in both languages! And what would it prove?

      PHP7 is mentioned in passing but it’s an alpha release. Speed tests look promising (reportedly twice as fast) but even that won’t catch Node.js.

    • angelxmoreno

      A Framework comparison would across two different languages would make little sense.

  • GisterMizard

    Good article, but unfortunately it’s nitpicking time :p. For #3, “0.1+0.2 != 0.3” is a floating point issue, not a js issue. Floating point arithmetic does not guarantee the distributive property d*(x0+x1+x2+…+xn) == d*x0 + d*x1 + d*x2 + … + d*xn. In this case, for javascript’s implementation it fails for d=0.1 and x = [1, 2]. I don’t know if 0.1*(1+2) == 0.1+0.2 works in PHP, but due to floating point limitations, there exists a very large number of possible values for d where the distributive property fails. So it’s not a fair to call that a javascript math error; all common languages and platforms have this problem.

    • Craig Buckler

      Fair enough but it’s one of the many criticisms developers have about JavaScript. Not that it causes many real problems.

  • http://glend.me Glend Gjermeni

    Node.js still lacks the quality of many PHP third party libraries. I wanted an oAuth2 client and server for e.g. but what I found were nothing close as the PHP counterparts.

    • Craig Buckler

      That’s why PHP won the integration round!

    • angelxmoreno

      I would not call it “quality” but instead call it “maturity”. Also, where did you look? PassportJS is what I use for oAuth2 client and node-oauth2-server for the server.

  • Ralph Mason

    Hey guys, in case you are interested, SitePoint’s PHP and JS editors have written a Right of Reply response to this smackdown: http://www.sitepoint.com/php-vs-node-js-smackdown-right-of-reply/

    Let the controversy continue!

  • troypc

    I felt like you really tryed hard to make the score draw.

    And also the importance of the rounds are not the same as we all agree. I think this is not a good way to compare two technologies.

    I would say the article is not written by a programmer, there is no numbers, no statics you are saying Node.js has a better performance but you are not showing any data.

    You really made a good start with giving number data like % 80 of the web uses PHP kind of things, but did not keep it up.

    Moreover it was a nice text to read. – Not article.

    • Craig Buckler

      Actually, I thought Node.js would win it by a mile but I think the result is fair.

      There are plenty of benchmarks proving Node.js is faster. Similarly, there are plenty of PHP benchmarks refuting it. Benchmarks are mostly futile – you can prove whatever you like.

      • troypc

        I wasn’t criticizing the result of the article, i criticized the workflow of it. Be calm, take your time and feel free to read my comment again.

        • Craig Buckler

          What additional statistics were you expecting? I presume it was the speed comparison because most rounds were either subjective or observations?

          There are benchmarks proving or disproving whatever performance comparisons you want to believe. I could only report from experience – Node.js is noticeably faster.

          Whether that’s true for all projects or your specific use is another matter.

  • nic

    >>”That said, SitePoint Smackdowns are not “use whatever suits you, buddy” reviews. ”
    >>”My advice: assess the options and and pick a language based on your requirements. ”

    u wot m8

    • Craig Buckler

      Bah – you caught me out! Although Node.js did win … just not by much.

      • nic

        hehe, I sure did. And right. Understandably so. It is almost two decades newer, after all. Node.js has incredible versatility that you can’t get with PHP. I write most of my desktop apps in it, and I sure would write any needed background tasks in it as well. It’s so easy to interface to.

  • Infiyaz Khalid

    Craig, thanks for your descriptive info. I never really even bothered to compare the two until now. In the early days of node.js, I presumed it must be yet another javascript framework like JQuery or Mootools.

    And after reading your comparison, I have decided never to go down the node.js path – smiles… I think it’s a matter of syntax with node.js that I just don’t like. For that matter, I use even plain old javascript only because I need some sort of client-end language and not by choice.

    Like you’ve said a few times, it’s subjective and after only about 8 years of php/javascript, I think it’s got to be some other alternative, if it comes to the point of looking for something like node.js.

    If I think I need real power that PHP can’t handle, I think I’ll go for one of my older languages like Pascal or C/C++.

    Thanks again!

    • Craig Buckler

      Glad to be of assistance!

      If you don’t like JavaScript, Node.js will never appeal. Personally, I love the language – quirks and all – but it took me many years to appreciate it. It’s not like typical OOP languages but, once you jump that hurdle, it makes others seem clunky (what d’ya mean I need to define a class before creating an object?!)

  • Aleksander Koko

    Good article Craig. Finally an article that compares the two languages really good. Didn’t knew that someone could compare those without some hate for one language (and in some cases for both of them :p )

  • https://devedge.eu/ Peter Petermann

    you can do non-blocking with php too, either by utilizing one of 3 event loop extensions or by building a stream select loop – like for example react php does.

    • Craig Buckler

      Yeah, but it’s not exactly built-in … or not until PHP7.
      Most languages have some way to either emulate it or – perhaps better – spawn other threads.

      • https://devedge.eu/ Peter Petermann

        1) in js its not buildin, its the node.js framework that provides it
        2) react php runs on a pretty default php install.
        3) there are implementations for PHP that literally use the same lib node.js does, for example https://github.com/phastlight/phastlight

        • Yoan-Alexander Grigorov

          Hi Peter.

          I agree that event loops are available in PHP, but the problem is that the whole layer of pre-compiled (and not only) extensions are not async based. The most vital part of software is frequently related to databases, and simply put, PHP would need to deliver asynchronous versions (with callbacks) for the database libraries. Those are currently not available as we all know and those functions will be still blocking. Sure, you can wrap them, but it would not be as fast as node.js in this particular example.

          The language itself has been designed to be io blocking. And I am not sure if this should change. I personally think that using threads is better than event loops.

          • Yoni L.

            Right, PHP7 will focus on thread safety management and communication instead of IO, even if react php is quite cool :)

  • Dmitry Kmita

    Thanks a lot for your article.
    I have been working with web-development for more that 5 years and can cay that every language is needed for it’s specific benefits. Depending on what you need in the end and what business requirements are, you choose technology stack you will use for developing it. NodeJS and PHP are two incredible languages for creating high-loaded and reliable server-side platforms, but we should not use any language just because of language. We should every time think which language would be best for creating specific needs.

    • Craig Buckler

      Hmm, yes, but projects are complex — no language is ever 100% perfect for every component and you’re unlikely to mix and match technologies. On the flip-side, you could argue that almost all projects can be achieved with almost any language.

      Ultimately, a developer will pick something they want to use. There may be better options but it’s impossible to research everything and you have to be pragmatic. Except for a few edge cases, PHP or Node.js could be used for any web system.

      • Dmitry Kmita

        Exactly, what I wanted to say is that complex projects cannot be created via 1 language. If you use 1 only because you know it better, but behind that there are a lot of performance losses – I think it’s not the right way. I’m not saying that you should always thing about best technologies and therefor have a lot of them in 1 project. No. Just before architecting the base you should think about technology stack that would be best for your needs. Just an example – some component that works with sockets on server side should be better implemented via Node.js, just because it’s easier to write and the performance will be better, there are also examples that should be better created on PHP, rather than Node.js.

  • Yoan-Alexander Grigorov

    Node.js is not so flexible when it comes to serious design (hey, you may include such round too). It took PHP a lot to acquire the advanced (most of) OOP aspects and it became very good at it. It is fairly easy to implement almost every pattern from P of EAA. Furthermore, Domain-Driven Design is also quite easily achievable, as the PHP community has very powerful ORM utilities such as Doctrine, for example.

    I just cannot say the same about JavaScript. Although you can mimic object-oriented capabilities, you are far from implementing some very handy patterns and follow even some of the most fundamental principles, such as the SOLID compilation, for example.

    Why do you need those, somebody could ask? Well, where JavaScript is heading others are just coming back. It is easy to work with document-oriented databases using node.js, but NoSQL is not everything and node.js is not the best choice for polyglot persistence, for example.

    IMPO node.js has been profoundly overrated. It is new, shiny yadi yadi yada, but it is not far from becoming even more dirty than PHP has ever been.

    • Craig Buckler

      JavaScript does not mimic object-oriented languages. If anything, it’s more object-oriented than most. Can you do this elsewhere?

      (function foo(x) { alert(x); }).toString();

      With a few exceptions, almost everything is an object in JS. It’s just that it’s not the classical inheritance you may understand from other languages.

      NoSQL databases have become more popular because of Node.js but to suggest that’s a problem is like saying PHP is bad because it popularized MySQL. Both languages support a multitude of data storage systems. PHP can use MongoDB. Node can use MySQL.

      • Yoan-Alexander Grigorov

        Hi Craig, thanks for your response.

        “it’s more object-oriented than most.” – interesting statement… hm maybe I am a bit more conservative. JavaScript still misses a lot of characteristics, which in turn stands in the way of implementing useful design patterns. Simply put, JavaScript lacks any kind of abstractions (correct me if I am wrong, I don’t keep a closer eye on JavaScript development), which basically give you great flexibility. It is a great language indeed, but it is more prototyped (if I can put it that way) than object-oriented (in the classical interpretation of the term).

        Not to mention that node.js is single-thread, and developers need to be aware that synchronization and scaling on multicore processors is not something that comes up with node.js, unlike languages that rely on threads (let’s consider Java for one good example). In fact, even PHP is simpler to scale. On each execution the appropriate core is just used. Maybe this is not so fast for the basic examples, but it is quite effective in the long run.

        Furthermore, it is quite easy to get lost in the callback hell when it comes to serious business logic with JavaScript, even if you use promises.

        P.S. You can put another round too – default values on function arguments. Guess who is the winner.

        • Craig Buckler

          You’re welcome.

          JavaScript is misunderstood. You don’t need to create a (class) template then instantiate an object. Although you can – it’s just not done in quite the same way as Java, C++ or C#. Classical inheritance is coming to ES6 although it’s syntactical sugar and I have my doubts about it.

          I mentioned Node.js is single-threaded – a long-running process for one user will stop all others. And I agree that callbacks can be difficult to manage. PHP is certainly easier to comprehend, but scaling is less certain. Both have challenges and it would depend on the type of application and architecture.

          OK – I’ll give you a point for default arguments (although they’re in ES6). But I’m going to remove a point for clunkier $ variable prefixes and -> arrow notation!

          • Yoan-Alexander Grigorov

            Well, I would agree only if it wasn’t so related to the syntax. $ and -> are design decisions, but they are working and they are there unlike the missing default values for JavaScript functions. I do not think that it is fare to remove points for things that you do not like in contrast for something that is clearly missing for no apparent reason. No offence.


        • http://www.developpeur-javascript.fr Benoit Hubert

          Just as Craig I’m both a PHP and Node.js dev.

          JavaScript is amazingly flexible and I don’t see where you couldn’t implement the same patterns as in other languages (there are good books on this topic such as JavaScript patterns).

          Your point about callback hell is true for beginner devs. I can easily remember my first Node app, with ugly “stairs” of deeply nested callbacks.
          You can totally avoid that and flatten your code using Promises (either native ES6 Promises or those provided by libs such as Bluebird). There is also the async lib for asynchronous flow control.
          It’s just a matter of time to get used to async programming, but then it gets as natural as anything you do on a regular basis.

          Default values on function arguments can easily be emulated in JS so it’s hardly an argument.

          Overall I think it is not really fair anyway to compare such different languages, and I think counting points is just plain ridiculous. No offense meant to Craig, his article is interesting but as someone said each comparing point will mean something very different to each programmer. So there couldn’t be anything more subjective. In both languages you can do ugly things and amazingly elegant stuff (I discovered Laravel this summer and quite liked building a fairly big project with it).

          PHP is kind of easier to start with. When you know it you can build things pretty fast. With Composer things have gotten a lot better to get your dependencies. Still I end up using Bower and Grunt to manage my asset pipeline for PHP apps :).

          As a backend+frontend dev I can easily say that having the same language on both sides is a HUGE win. With Browserify you could already share modules between Node and the browser, and it’s getting even easier with ES6 modules. Now THIS is a non-subjective argument :).
          As for DB integration if you take Sails.js it can work with no less than 16 DB engines (among which mongoDB, MySQL, PostgreSQL…).

          The argument about having more frameworks in PHP (that someone invoked earlier) is also about to become obsolete, with mature Node.js frameworks such as Sails, Koa, Meteor…. Take the number of frontend frameworks, so many came out in a fairly short time. Pretty soon I expect it to be the same for server-side frameworks.

  • Russell Searle

    I understand that your smackdown emphasized the technical merits of the languages, which is of course the main point of interest for Sitepoint readers. But if you fought Round 9 on Programmer Passion, then I think it would have been fair to fight a round on the number of applications in the field built on the two platforms; the number of ready to run solutions available on each. I don’t think there is much doubt that PHP would win that round by a country mile, so far in front that Node.js (and many other contenders) may never catch up.

    • Craig Buckler

      You could go by that metric. Similarly, you could say almost every web page has some JavaScript therefore JavaScript wins.

      There has been an explosion of Node.js projects during the past few years. It’s difficult to quantify and it may not last but I don’t think PHP has matched that level of output during the same period. Of course, there have almost certainly been more WordPress deployments than Node.js projects but that’s reusing an existing project rather than creating new ones.

      • Russell Searle

        I’ll take your word for it, but do you have any source that tracks the growth of Node.js projects?

        And I wasn’t counting WordPress as multiple apps. I agree with you that despite the number of WP sites, WP is only one product (notwithstanding its community extensions).

        I think we may be looking at this point from two different angles. Maybe you are looking at PHP vs Node.js dominance in terms of language choices to undertake new development; while I would not develop a new app for a solution if an existing app (albeit modified or extended) would meet the need.

        On that score I think PHP has the numbers in terms of existing solutions (and the ongoing enhancement of those solutions), but you may be right that Node.js has explosive growth in terms of the development of new solutions.

        • Craig Buckler

          You could go by npm – which has 164,000 modules. PHP’s Composer has 64,000.

          If you need a full installable solution, PHP wins. It has a massive choice of CMSs, project managers, email clients, etc to choose from. But that’s because PHP’s been around longer – not because developers are necessarily more passionate about it.

      • Tomb Raider

        It’s not about WordPress only. PHP has many ready to use frameworks like Laravel, Symfony, CakePHP, Phalcon, etc.

        Plus, comparing PHP with Javascript to give to edge to NodeJS would be unfair, the javascript we use in browsers are DOM dependant javascript codes and have no advantage for Node.js developers (provided how many websites are powered by jQuery).

        • Craig Buckler

          I was making the point that the winner in each round can be argued in different ways to support your view. More applications are written in PHP because it’s been around considerably longer – but that doesn’t make PHP “better”. Nor is Node.js better than PHP because almost every PHP project uses JavaScript.

          The JavaScript we use in browsers is identical to Node.js – it’s the same V8 engine as Chrome. It’s only that you’re not normally interacting with a DOM (although you can). It’s the same language, structures, syntax and event models. I wouldn’t suggest knowing client-side development suddenly makes you a server-side developer but having the same syntax both ends is useful (I’m forever using dot methods in PHP or arrows in JS).

          And jQuery’s written in JavaScript to help JavaScript developers write JavaScript. It couldn’t be more JavaScripty!

  • http://dada.theblogbowl.in/ Shaumik Daityari

    Actually, a hello world in PHP is even smaller.

    Just type “hello world” in a text file and save it with a PHP extension and it would do the trick!

  • Nikola B.

    I’d like to chip in with a few observations.

    Hello world is not a fair comparison really. Both techs are equally trivial to output hello world. Node would use either console.log(‘Hello world’) and php doesn’t even need an echo statement. Technically, if one wants to dish out HTML / JSON – both technologies allow to do so in a very simple manner. You just showed how to boot up a server in the JS code, and that apparently makes it more complex.

    The syntax – is it really so hard to overcome simple things like counting a number of characters in a string? It’s really THAT confusing, even after so many years? All the articles that mention that PHP is a mess often use that stupid argument about method inconsistency – if you’re not mentally challenged, this “inconsistency” will usually span to a few, rarely used functions – and it’s quite trivial to overcome. If someone deals with multiple languages in their day-to-day work, this issue is almost nonexistent. Swapping between different syntax and purpose is much more difficult than to remember that a few methods might have arguments swapped around.

    What’s funny is that you mistook the syntax with method signatures. Quite silly, given the fact that there are only a few syntax differences between these two languages, and a sharp eye will notice that both languages are similar to C – how can you compare the syntax? Why not compare language features? You provided zero mention about that, yet you award JS for a cleaner syntax. Apples and oranges and the winner gets a plum.

    Development tools – again, you compared a fully fledged server with a language and your conclusion is that node wins because it *usually* comes with npm when performing installation. Why not compare the LACK of development tools? Both of what you compared apparently have great dev. tools – I’d call it a draw there.

    Hosting and deployment – technically, it’s easier to set up a computer that provides results via node.js than it is with PHP. The fact that there are (still) some shared hosts means nothing in the grand scheme of things. Also, FTP-ing? Year 2015., we have GIT and various other awesome tools, who the hell FTPs stuff? And no mention about avoiding FTP and reasons why? Apparently people read your articles, why not mention bad practices and provide alternatives?

    Performance – node.js doesn’t have an interpreter really and it’s generally faster than PHP – this has its roots in how V8 operates. However, let’s check some other things that you wrote:

    – Fewer Dependencies – not true. PHP has the famed fastcgi process manager or php-fpm. It works nearly exactly as node – listens on a socket. They have exactly the same process of booting up – you either do /etc/init.d/php-fpm start or node myfile.js – nearly the same process. If you don’t serve PHP via FPM – you should, the mod_php way is obsolete, slow and stupid way of serving PHP.

    That also means that web server starts no php interpreter. You should be accurate about which SAPI you write about.

    – Applications are Permanently On – if we look at PHP-FPM – this is also true for it. And that’s why it exists in the first place – to cache most common actions, such as connecting to a db etc. – php-fpm will keep connections in a pool and reuse them. That’s why applications that are served via php-fpm are typically faster than stupid solutions using Memcached or Redis for database caching – if there’s no overhead of connecting to a database, it’s always quicker to just select data from the DB (which is properly configured) and leave out the in-memory storage solutions where they should be – in the trash.

    – An Event-driven, Non-Blocking I/O – newsflash – it exists for PHP as well. The only difference is that it’s not widely used. You can’t mention that one tech has something and the other doesn’t if it’s not true. If you googled for “php async mysqli” you’d get a manual excerpt that shows you how to perform async mysql queries in PHP as well.

    I won’t go further. My conclusion is that you simply don’t have sufficient knowledge to compare technologies. You didn’t do your homework. You wrote about the things you know – which seems to be dated at least 10 years. The saddest part is that you spread false knowledge – and no matter how much you might disagree with me – that’s a fact. And we all know that false knowledge is much more dangerous than no knowledge.

    • Erik Thiart

      What do you prefer, node or php for someone who only did frontend and want to start moving into a more backend developer role focusing on websites. You seem like the right guy to ask, sitepoint should pay you

      • Olav Alexander Mjelde

        You have to consider what you want to do, e.g. if you want to run your own wordpress site/multisite and make extensions, PHP might be your safest bet as a first entry into the server side. If you want to just make random stuff to test it out, why not test several languages and see what you like the most?

        The great thing about testing PHP as such, is that you can get cheap hosting “everywhere” that you can test on, or you can run LAMP or WAMP in your own localhost with a very easy install… (one liner), you can of course write php code (and node.js) with a simple editor like vim or on windows notepad++ or maybe the sublime text on windows, mac etc.

      • Eric Maier

        node. its worth the investment and nobody uses PHP but old people anymore. :(

        • Sojimaxi

          not true… even the biggest companies run blogs and they do it on php

      • Peter Pottinger

        Go with LAMP, its much more flexible and will serve you better in more use cases over the long term than MEAN which has a very limited use case.

        • Craig Buckler

          MEAN is more limited but this article does not compare LAMP and MEAN. Node.js can connect with MySQL or use a front-end web server. PHP can connect to MongoDB and use AngularJS on the front end.

          For ease of initial learning, PHP is simpler. I would also suggest that MySQL is a better database to learn first because SQL is more widespread than MongoDB and other NoSQL systems. However, when it comes to application development, go with whatever you prefer…

    • music

      Thank You Mitch.
      I agree, the above was written by a person who doesn’t know php & node in depth. And such articles should only be written by very very knowledgeable people when its on a place like sitepoint. Else it misleads people.

      (People with half knowledge are more dangerous than people with none. :-)…)

    • Hans Henrik Bergan

      mod_php is NOT slow.

      benchmarking nginx+php5.5-fpm+unixsocket vs apache+mod_php5.5+MPM_worker , apache handled more php requests and faster in my tests. trouble is when serving static content, apache used far far more resources per request than nginx. tested it a couple of years ago though.

      • Ján Stibila

        hard to tell which is faster from that comparison. it all depends on how well tuned is configuration and I bet that you could get good boost with proper tunning fpm.

    • Peter Pottinger

      Correct, its so difficult to find proper comparison articles due to the limited knowledge on the authors part. Out of 10 node.js vs php articles I’ve read today, all 10 of those authors have limited, outdated, or entirely incorrect information about each technology.

      • Craig Buckler

        Perhaps you should check the date first? This article’s almost two years old! That said, it remains mostly relevant. Did anything specific concern you?

  • virtualCableTV

    Looking at this from a business perspective after all these years I’ve finally delved into WordPress hence by proxy I must now learn PHP as there is a lot of life left in WordPress if you know where the next big thing to take advantage of WordPress is emerging.

    And I do. lol

  • tam

    very good

  • Ilya Geller

    All programming languages are obsolete and shall not be used anymore.
    I discovered and patented how to structure data. That means computer can understand human language without any intermediates.

    Who needs all computer languages, which structure human language partially, some portions of it, if I structured it all and automatically?
    Who needs programmers, who manually structure common human speech?

    The era of programming is over. Thanks and buy. You all are fired.

  • Bob Kline

    I was a bit surprised that the native advantage with Unicode didn’t come into the comparison.

  • Sven

    I would be interested on security concerns in this context. Would be very interesting to have a round about that aspect. Would you be able to add one more round?

    • Craig Buckler

      Neither PHP, Node.js or any other language is inherently insecure. The odd issue is reported but they’re normally fixed quickly. It’s more likely that the application you write using that language is insecure.

      I’d make it a draw. You could argue there are more PHP developers and applications so it’s a bigger target but that’s a success rather than a drawback.

  • Leonardo Mauro

    I realy liked this smackdown.
    I love PHP, and recently start with Node.js.
    I had “the back foot” with this new technology, but you help me understand more about the Node.js


    • http://cabreralawoffices.com/ Peter Cab

      Please guide me I am a beginner and Just started Node.js.But I am confused either I shoud go with it or not?

  • dsstrainer

    Some good points… some were nonsense wins towards node.js when they were clearly in favor of php, even in your own words. We’re looking like more of a 6.5/3.5 in favor of php, again based on your actual words.

  • http://www.cygnet-infotech.com/ Hemang Rindani

    SitePoint is a great platform that works on lavarel to build highly scalable Enterprise Content Management Systems. Workflows in Sitepoint helps a business to implement any complex business requirements which are evenly supported by number of themes and modules to cater the needs. PHP, the base of Sitepoint is a language that is easy to understand and with little knowledge, developers can create wonders. Due to the popularity it is exposed by certain threats and thus make sure to go through the security guidelines and use the functions that are reliable.

    Node.js is for the developers that are proficient with Java and can create some great designs, but because of the simplicity, I suggest using PHP which is equally proficient.

    • http://srph.github.io/ srph

      What does Node.js have to do with Java?

    • SWR

      What a fucking retard…

  • http://www.indiobailbonds.com/ Indio John

    I am so surprised to know that PHP is getting over now? Node.js is replacing other tools.Is it true?

    • Marcello Kad Cadoni

      Is english better than italian? Is french replacing deutch? They are just different languages. In most cases the problem resides inside people’s brain, not so smart to produce decent algorithms. This kind of VS comparition articles are too funny

      • http://www.indiobailbonds.com/ Indio John

        YuP, you are totally right. But even now my clients wants to develop their projects in Node instead of Php.

    • Sojimaxi

      don’t think so ….not even in the near future! :)

  • Max Chau

    Maybe I’m not a super hero in PHP, but I’m sill discovering new things and ways to write PHP with over 10 years experience. I’m still reading PHP articles that’s why I’m here.

  • Charles Bryant

    I have built lots of projects in both PHP and node.js, I think my conclusion with node is I am not really a fan, if I had to build a project today, choosing node.js (with express) or php (with laravel) I would almost certainly choose php.

    I would have liked to have seen a comparison between the object model, for me the best feature in php is the ability to program against interfaces.

    Another issue I have with node is as it is a newer technology, things start to go wrong, memory issues etc, you build an app today in php and it will run for as long as needed, the apps I have helped build have all run into some issues.

  • Greek Gastone

    LOL about another “Coldfusion is dead” mention when v.11 released one year ago.

  • angelxmoreno

    I wonder how many developers in the comment section are actually good at both PHP and NodeJS. I use both all the time. “Best tool for the right job” will win everyday. Neither is better than the other as a whole. Both are better than the other at VERY specific things.

  • Marcello Kad Cadoni

    joomla XD ahahahah i’m joking. Since it’s just a project for an exam, use pure php without framework, at least you finish it soon instead of learn frameworks and blabla.

  • Marcello Kad Cadoni

    When i read this kind of article i feel like a girl that read blog about nails… >_<

  • code

    PHP is easy to learn, hard to master. You will find very few php programmer who can really write elegant systematic design pattern. But it is powerful language, Node is getting there but PHP is already on the top and moving further.

  • Eric Maier


  • Eric Maier

    phantomjs is nice, express is fast and node’s load time is half compared to iis and apache. the libraries are growing everyday in npm. each technology has its benefits. for corporate use microsoft. but what i like about node is something i cant get from any other technology. with a testable architecture i can share the rules on client and server with a single file. i like nodejs and will continue to use it after 14 years of iis. intellij idea is a nice ide compared to visual studio. mono is microsoft’s most impressive technology, everything else is for corporate.

  • Unknown

    What makes me sad with Node JS, or frameworks like backbone or Angular. Now you have people who have NO clue how to structure their code and just throw in components without an after thought of how their code should be structured.

    It is more disheartening when I see frameworks used when they are not even needed.

  • Jasterrr

    As others pointed out, this article is so misleading. Thumbs down!

  • Thomas

    What about a Node vs. Laravel 5.2 with PJAX and AJAX? Laravel 5.2 also has web and api middleware groups…

  • tzs007

    Life saver! I just started to learn Laravel in this week. Earlier I used Code Igniter (I love it, but it has lack of support yet). I liked that atmosphere and new things around Node.js, but I’ll learn Laravel instead.

    Good article, thanks.

  • https://findmate.asia PinaLove

    You’re comparing apples and oranges here. PHP is better compared to Python, Ruby, et. al.

    In over 10 years of programming with PHP and other similar languages I’ve never had an issue of performance at the app level. PHP & Node will never truly be the bottleneck to performance, it will always be in your persistence layer.

    • Craig Buckler

      Why shouldn’t PHP and Node.js/JavaScript be compared? They’re both programming languages primarily designed for the web (unlike Python and Ruby which were devised before it existed).

      PHP isn’t slow and PHP7 certainly closes the gap but, in my experience, Node.js is considerably faster. Why is your experience more valid? Why shouldn’t processing speed be compared?

  • Adrien Horgnies

    I’m novice in both PHP and JS but I can clearly see this article is biased in favor of node.js. I’ll use PHP because of its immense popularity (assistance, libraries, frameworks, …) but I’d like to use node.js because I prefere to manipulate DOM objects (or JQuery objects for that matter) rather than strings. Also, I find JS easier to read in comparison of PHP, but that may be because JS is closer to what I already know (Java, C, C#, Bash).

  • Роман Кузнецов

    PHP is easier and cleaner than Node.
    PHP uses classes and not prototypes. Classes are far more better they have private and protected methods and properties and constants and traits and all the other GOOD staff which JS hasn’t and won’t have at all
    PHP can work in the way node does it..

    Node is just a fashion. Node is just a way to say: Hey I know JS only and it’s enough for web development )))

  • Konstantin Starojitski

    Round 3: Language syntax. Constantly having to type $ and -> and [‘key’] in associative arrays in PHP is a chore. That alone makes PHP feel clunky. And don’t forget things like CoffeeScript and ECMA6 that make PHP look like a verbose monster.

    Round 9: Programmer Passion. Compare the number of watchers and stars at git hub :
    Node.js Watch: 2,027, Stars: 30,241
    PHP Watch: 1,303, Stars: 10,561
    And while the numbers for PHP include the language itself, the numbers for Node do not include Javascript language. It seems while there are maybe many more users of PHP, there are at least twice as many people involved with development of Node than with that of PHP. My feeling is that among Node using developers there are more those who are passionate about programming in general than among PHP developers. Maybe not in absolute numbers but almost definitely in relative.

  • p155

    You lost my respect when you ended your php file with ?>

    • Craig Buckler

      That’s strange. Your comment makes me want to give you a big cuddle and tell you everything’s OK.

      Look closely and you’ll also find I did my indentation using the opposite tabs/spaces that you use.

  • Nemanja

    Very good “VS” article! You’re being very objective, very good job!
    Nothing is black nor white, like some folks like to present!

    I believe in statement “use the proper tool for the job”, thus in PHP app I can use node.js for what it’s best at – async execution model!

    Hybrid apps and microservices are the best these days, so there should not be “vs” rally!

  • H. Elwood Gilliland III


Get the latest in Front-end, once a week, for free.