Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

PHP vs. Node.js: An epic battle for developer mind share

Peter Wayner | Jan. 13, 2015
Here's how the old guard and upstart darling of the server-side Web stack up against each other.

Where PHP wins: Deep code base
The Web is filled with PHP code. The most popular platforms for building websites (WordPress, Drupal, Joomla) are written in PHP. Not only are the platforms open source, but so are most of their plug-ins. There's PHP code everywhere, and it's waiting for you to download it, modify it, and use it for your needs.

Where Node wins: Newer code means more modern features
Sure, there are thousands of great open source PHP files, but some are 8-year-old WordPress plug-ins hoping and praying that someone will download them. Who wants to spend hours, days, or weeks monkeying with code that hasn't been updated in years? Node.js plug-ins are not only newer; they were built with full knowledge of the latest architectural approaches. They were built by programmers who understand that modern Web apps should push most of the intelligence to the client.

Where PHP wins: Simplicity (sort of)
There's not much to PHP: a few variables and basic functions for juggling strings and numbers. It's a thin layer that doesn't do much except move the data from port 80 to the database and back. That's what it's supposed to do. A modern database is a magical tool, and it makes sense to leave the heavy lifting to it. PHP is the right amount of complexity for a job that's not supposed to be complex.

Where Node wins: Complexity of closures and more
JavaScript may have many little idiosyncrasies that drive some mad, but for the most part it is a modern language that sports a modern syntax and a few useful features like closures. You can reconfigure and extend it easily, making powerful libraries like jQuery possible. You can pass functions around like objects. Why limit yourself?

Where PHP wins: No client app needed
All of the talk about using the same language in the browser and on the server is nice, but what if you don't need to use any language on the browser? What if you ship the data in HTML form? The browser pops it up, and there are no headaches or glitches caused by misfiring JavaScript threads that try to create a page on the browser from two dozen Web service calls. Pure HTML works more often than anything else, and PHP is optimized to create that. Why bother with JavaScript on the browser? Build up everything on the server and avoid overloading that little browser on the little phone.

Where Node wins: Service calls are thinner than HTML-fat PHP calls
While AJAX-crazy HTML5 Web apps can have too many moving parts, they are cool -- and very efficient. Once the JavaScript code is in the browser cache, the only thing that moves along the wires is the new data. There's not a ton of HTML markup, and there are no repeated trips to download the entire page. Only the data has changed. If you're willing to put in the time to create a slick browser-side Web app, there's a big payoff. Node.js is optimized to deliver the data and only the data through Web services. If your app is complex and data-rich, it's a good foundation for efficient delivery.

 

Previous Page  1  2  3  Next Page 

Sign up for Computerworld eNewsletters.