- back to the house
- Development of software
- Development of software
- PHP is a scripting language.
What are the differences between the old guard and the upstart darling of the server-side web? Let’s compare and contrast.
However, hype fades over time, and software can last for decades. It’s not the same PHP code that was used to power your grandmother’s website. The majority of the PHP code base will not migrate, and it will continue to serve large portions of the text we read on a daily basis. Part of this is due to the fact that PHP is still being reborn. According to some estimates, PHP is used in some form on 40% of the pages we visit. The guts of PHP-based systems have been completely rewritten in the last few years.
So, if you require these features, you won’t need to look for a more comprehensive stack. Many of the same clever on-the-fly optimizations that V8 brought to Chrome and Node.js are now available in PHP 7.2 and the HHVM. Thanks to the same smart techniques that propelled the Node.js revolution, PHP’s zippy, just-in-time compiler is delivering answers faster than ever. Furthermore, HHVM includes Hack, a clever PHP dialect that fully supports advanced programming features like lambdas, generics, and collections.
Where PHP shines is when it comes to combining code and content.
Perhaps you’d like to include text or data from a database. There are no extra files or complex architectures required; all you need is programmable logistical power at your fingertips. You’re typing away at your keyboard, converting your thoughts into text for your website, and you want to add a branch to the process, a simple if-then statement to make it look nice, say, depending on a URL parameter. In PHP, you simply open the magic PHP tags and begin writing code in a matter of seconds. There’s no need for templates because everything is one!
Separating concerns is where Node comes out on top.
Mixing code and content is a crutch that can lead to your demise. Sure, the first two or three times you do it, mixing code and HTML is entertaining. It’s simpler to understand and maintain for new programmers. Real programmers add structure and divide the logical and cosmetic layers. However, your code base will quickly become a tangled mess of logic. Node.js frameworks are created by programmers who understand that having a separate model, view, and controller makes life easier.
Where PHP excels is in its extensive code base.
The platforms, as well as the majority of their plugins, are all open source. PHP is used to create the most popular website platforms (WordPress, Drupal, and Joomla). PHP code can be found all over the internet. There’s PHP code all over the place, ready for you to download, modify, and use for your purposes.
Node wins because it has more modern features.
Sure, there are thousands of excellent open source PHP files available, but some are 12-year-old WordPress plug-ins hoping for a download. There is a dusty, long-forgotten library for every modern version of Symfony that no one updates.
They were created by programmers who understand that the majority of the intelligence in modern web apps should be pushed to the client. Not only are Node.js plug-ins newer, but they were created using the most up-to-date architectural approaches. Who wants to tinker with code that hasn’t been updated in years for hours, days, or weeks?
Where PHP comes out on top: Simplicity (sort of).
PHP is a simple language with only a few variables and basic functions for manipulating strings and numbers. PHP has just the right level of complexity for a job that isn’t supposed to be complicated. That’s exactly what it’s designed to do. A modern database is a magical tool, so it’s only natural to trust it with the heavy lifting. It’s a simple layer that does nothing but move data from port 80 to the database and back.
On the other hand, if you’re a programmer who wants to do more than interact with a database and format the results, PHP now allows you to do so without straining your neck. Using this constrains your code to only run on the HHVM, but that isn’t necessarily a bad thing. Hack, a complete language with modern features like type annotations, generics, and lambda expressions, is now supported by Facebook’s HHVM. It moves at a breakneck speed.
Where Node excels: the plethora of language options.
Where PHP excels: There is no need for a client application.
Node wins because service calls are lighter than HTML-heavy PHP calls.
SQL is the place where PHP triumphs.
Because some of the most stable and well-developed code interacts with an SQL database, all of that power can be easily integrated into a PHP project. With a few changes to your queries, you can switch your code. If MySQL isn’t quite right, Oracle and Microsoft both have excellent SQL databases. PHP was designed to work alongside MySQL and its many variants, such as MariaDB. The vast SQL universe has no boundaries. It isn’t a perfect, happy family, but it is a large one. Not only that, but the database world is gradually improving as developers discover ways to add more intelligence to the database, reducing the amount of work you have to do.
JSON is where Node.js shines.
Where PHP excels is in coding speed.
For most developers, writing PHP for web apps feels faster: no compilers, deployment, JAR files, or preprocessors are required—all you need is your favorite editor and a directory containing PHP files. Your mileage may vary, but PHP is a good tool to use when you need to get a project done quickly.
Where Node.js excels: application performance
Competition is where PHP comes out on top.
This can only mean better results. The HHVM and Zend teams are working hard to provide everyone with fast code. Independent benchmarks are popping up, and everyone is pushing their code bases to their limits. The battle for PHP developers’ hearts and minds is still going on.
Solidarity is a place where Node.js triumphs.
Competition is beneficial, but fragmentation is inevitable. What happens if your code only runs on one of the two platforms? It doesn’t matter how good the competition is if you have to spend weeks or months rewriting your code. Is it really necessary to have two different code bases? While Node.js had its own splintering a few years ago, the Node.js universe has since reunited with the launch of io.js, giving it the kind of language solidarity that PHP developers may soon crave.
Basic apps are where PHP shines.
PHP is an obvious choice for any team that wants to keep the intelligence on the server and not on the client. The teams building static site generators (463 as of this writing) and stripped-down webpages in the AMP format are part of the backlash against this rococco insanity.
Node.js excels in the following areas: richness
Headless is a scenario in which both parties win.
This may not make sense for someone starting from scratch, but if you’ve been using PHP for a long time and want to progress slowly, this can be a good compromise.
Microservices and serverless are two areas where both win.
Peter Wayner is a contributing editor at InfoWorld and the author of over 16 books on topics ranging from open source software to autonomous cars, privacy-enhanced computation, digital transactions, and steganography.
2019 IDG Communications, Inc. Copyright ©