PHP Vs Node
PHP Vs Node
PHP Vs Node
js
Where PHP wins: Mixing code with content
You’re typing along, pouring thoughts into text for your website, and you want to add a
branch to the process, a little if-then statement to make it look pretty, say, depending on
some parameter in the URL. Or maybe you want to mix in text or data from a database.
With PHP, you open up the magic PHP tags and start writing code within seconds. No
need for templates—everything is a template! No need for extra files or elaborate
architectures, only programmable logistical power at your fingertips.
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.
And while JavaScript has many little idiosyncrasies that drive some mad, 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: 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.
Then again, if you’re a programmer who wants to do more than interact with a database
and format the results, you can now do more with PHP without holding your nose.
Facebook’s HHVM adds support for Hack, a complete language filled with modern
features like type annotations, generics, and lambda expressions. Using this limits your
code to running only on the HHVM, but that’s not the worst thing in the world. It’s very
fast.
If you were to imagine the perfect book to describe IT organizations right now, it might
be entitled A Tale of Two Clouds.
The backlash against this rococco insanity can be found in the teams building static site
generators (463 at this writing) and stripped-down webpages in the AMP format. PHP is
a natural choice for any team that wants to concentrate the intelligence on the server so
the client isn’t overburdened.
If you’ve got quite a bit invested in PHP code running on the server, this may be a way
to enjoy the best of both approaches. The old, established PHP code acts as a front
door to the database, double-checking the requests, cleaning up the data, and generally
providing all of the business logic. The client side is a progressive web app written with
the latest JavaScript framework. When it needs information, it sends off an AJAX
request to the PHP code.
This may not make sense for someone starting from scratch, but if you’ve relied upon
PHP for years and you want to move forward gradually, this can be a happy
compromise.