PHP was designed to die

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:

  1. Single node performance
  2. Scalability

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

  • Its excellent scalability mitigates its (constantly improving) single-node performance.
  • It has decades-long experience of delegating tasks its not best at to other tools (caching by reverse proxies anyone?)
  • It is very simple to start with
  • But also has mature frameworks that follow best design practices
  • It can be hosted anywhere, be it shared or private hosting
  • Although it claims to be a universal programming language (i.e. you can develop not only web applications), it's web what if was designed for, and what it does best.

like it or not

The elephant will continue to dance


Kirill Roskolii

Passionate about Drupal and other FOSS software engineer

3 个月

Deep and thoughtful as usual, bravo Valery Lourie !

要查看或添加评论,请登录

Valery Lourie的更多文章

  • Phase 2, week 4. Decision fatigue

    Phase 2, week 4. Decision fatigue

    (Image courtesy https://desktime.com/, distributed under Creative Commons) Disclaimer 1: This is the second version of…

    2 条评论
  • Phase 2, week 3. Who's there?

    Phase 2, week 3. Who's there?

    This week's goal for Zodiac Zingers, as I mentioned in my previous post, was to install visitors statistics/analytics…

    1 条评论
  • Phase 2, week 2. Spread the word

    Phase 2, week 2. Spread the word

    Last week I fixed the site's homepage, changing it from a single horoscope card of the current sign (Scorpio as in…

  • Phase 2, week 1. Man in the middle

    Phase 2, week 1. Man in the middle

    How it all begun. "Man in the middle" could be my personal motto when it comes to politics (I place myself neither far…

  • Phase 1: complete

    Phase 1: complete

    Several days have passed without updates on my #ZodiacZingers challenge, but I have a good excuse - without experience…

    4 条评论
  • Day 8. Waiting for XB

    Day 8. Waiting for XB

    Read from the beginning One thing that I noticed yesterday, is that on the first load of the card page, it loads quite…

  • Day 7 ?Sprechen vous espa?ol?

    Day 7 ?Sprechen vous espa?ol?

    Read from the beginning Yesterday, I've made some modifications to the site theme. To check if those were effective…

  • Day 6. Not great, not terrible.

    Day 6. Not great, not terrible.

    Previous day and what's the deal. Dealing with the site theme is another "new feature" (for me it is) I'm trying in…

  • Day 5. Eat your own dogfood

    Day 5. Eat your own dogfood

    Previous day and what's the deal. As I mentioned on day 2, I use ddev for the local development.

  • Day 4. Making the first prediction

    Day 4. Making the first prediction

    On Day 3, I've evaluated 2 modules that will be in the heart of Drupal CMS: project browser and ai. Time to write our…

社区洞察

其他会员也浏览了