PHP was designed to die
Latest #WordPressDrama has triggered another wave of predictions of near PHP death (and as a conclusion, suggestions to rewrite popular PHP products in other languages), which has reminded me an excellent article (and gave me the title of this post).
PHP was designed to die, and die quickly. Just not in the way its haters suppose.
The core PHP feature follows the most simple programming workflow: get input data, process it, display the output, and die.
It's not that PHP is not capable of running for a long time, but it was never the goal.
Missing the full picture.
There are 2 parameters that define application performance in production mode:
Single node performance is how fast the application executes certain task set. Measurement here is amount of time needed (the less the better).
Scalability is the ratio of performance gain caused by adding another node (100% being the highest possible value).
It's important to note, that in all practically important cases application performance (single- or multiple-node) depends not only on the speed of the application language, but also the speed of other services it relies on - network connection, database servers, 3d party web services etc.)
Imagine the scenario where the task set is "serve 100 hundred simultaneous requests to the home page", and applications A and B are written in different languages.
Application A: 1 node completes the task set in 10 seconds, 2 nodes - 6 seconds, 10 - 1.5 seconds.
Application B: 1 node completes the task in 5 seconds, 2 nodes - 4 seconds, 10 nodes - 3 seconds.
领英推荐
You can tell that application A is less performant, but more scalable. There is always a point (defined by the single-node performance difference), after which more scalable applications start to win.
You can easily find some infographics of <other languages> performance putting PHP to shame.
The issue is that all those funny images make fun of PHP performance on a single node. And let's face it - PHP is not the fastest programming language. Never was, probably never going to be (although performance gets better with every version).
The irony
What makes PHP so enduring to time, is its design to die quickly and the "shared-nothing" principle. Typical PHP application instance doesn't care about existence of other instances, because all the application data is stored somewhere else.
So, in theory, if you add another PHP instance to the picture, overall performance should grow twice (100% scalability). You add 10 servers - performance should grow 10 times. This is never the case, but the real numbers are really, really close, if dependent services like DB server have decent resources.
The same "shared-nothing" approach can be implemented in other languages, that's true. But it's much harder to orchestrate the nodes in, say, express.js (which is a web server by itself and doesn't need helpers like apache or nginx). Why would you care about sharing application data elsewhere, when it can be stored in the node's memory? This is faster, but not scalable at all.
No matter how fast your JavaScript is (or how you believe it to be), it will get to the point when PHP beats it. Depends on the usage, of course, but let's be ambitious :)
There are number of reasons PHP is here to stay
like it or not
The elephant will continue to dance
Passionate about Drupal and other FOSS software engineer
3 个月Deep and thoughtful as usual, bravo Valery Lourie !