Why is PHP so popular?
Just the Gist
Many factors are at play, but the most important factors for PHP's popularity are:
Flexible and ...
For further actions, you may consider blocking this person and/or reporting abuse
I've been a PHP developer for more than a decade already (after 15 years in videogames development) in a big web company with millions of users.
I can tell you that PHP (7.x onward, forget PHP 5 at once) is a fantastic language, very accessible, flexible and and really really easy to learn.
We just released a brand new backend API fully developed in-house in PHP 7.4, built on top of the lightweight Slim 4 framework (used exclusively for route management and PSR-7 stuff). Served with nginx/lua+php-fpm the performance is fantastic, and serves more than 1 million active mobile app users withouth a hitch.
Some notes:
1.- If you want PHP for heavy duty stuff, like an API, run away from things like Laravel and don't look back. Those are overengineered performance sinkholes.
2.- Program your own SQL queries. ORMs are a big waste of performance, and an optimization nightmare.
3.- If you can, don't use a simple plug-in caching solution like CloudFront or Varnish. A custom Redis caching system developed in LUA (under nginx) is blazing fast, and as flexible as you want it to be.
4.- Keep your dependencies to the bare minimum, and I mean it. If you can develop your own solution for a problem, don't just go to "composer require ...". Dependency hell can be a real pain, and some popular modules are so generic and slow that can be more of a problem than a solution. Pick wisely, and test thoroughly.
5.- Conceptually, PHP is a framework in itself. It has already integrated a lot of services and interfaces that for most languages are external dependencies and libraries/drivers. Use them, they are available right out of the box, and work just fine and efficiently.
6.- WordPress is not a good example of what PHP can achieve. Its just the contrary, a hugely bloated mess. PHP can do waaaay better things than WordPress.
7.- For extreme performance, get rid of nginx+php-fpm and use Swoole. With Swoole, PHP becomes a real beast.
I know PHP 8.1 can do most Swoole-like things, but its so new I didn't have enough time to test it properly.
Thanks sobukus. These were some excellent points! Thankfully I started learning PHP with 7.1, and am currently exploring everything neat with 8.1. I haven't gotten to use Slim (I've mostly done Symfony) so I don't know much about it. But it sounds like you are putting it to some real good use. But a small scale framework I've recently checked out is framework-x. It's built upon ReactPHP and make use of Fibers under the hood. I have no idea how it would perform in a race against Swoole but I believe it has a shot.
Very interesting. I didn't know about Framework-X, but looks really neat. I will take a good look at it.
For these things the PSR-7 standard is a real bliss. Swapping different PSR-7 frameworks, like in this case with Slim 4 and Framework-X, should be a breeze.
Swoole is a bit special, as it is not PSR-7 conformant, and uses its own request/response formats. This means that for Swoole you need a small translation layer to make it PSR-7. Not a big deal, but not as clean as it would be if it was already PSR-7 from the get go.
A new toy to play around with! Well, there goes my sleep-time...
Thanks a lot for the hint :)
I've been working with PHP since 2004.
I totally agree with #1 and #2.
Laravel is good for some but it's really bloated and you have to follow what they think is the best way.
Know your SQL. ORMs have their place but to really know your project/product, dig in and understand your database and SQL.
I don't agree with your thoughts about WordPress.
Currently WordPress plays a huge role in keeping PhP alive a really vibrant WP community that attracts daily contirbutors. Almost half of the web is based on WordPress what else best do you expect from PhP to do?
I agree that WordPress is a popularity behemoth. In fact we use it as CMS in our company. The merits of WordPress are unquestionable, and I sincerely respect its success as such a cornerstone of the web.
But the way in which WordPress grew up organically to its current size and the lacking documentation for developers causes things to get messy whenever you want to do some advanced things. Last time I had to do some internal stuff I had to actually debug the inner workings of WordPress itself to make our code fit in the process and work as intended. And the "what will break?" feeling whenever we update WordPress gets me uneasy.
As a front end renderer, it gets very slow under heavy work, so either you have to cache like crazy or replace the front end part. We are currently replacing all the rendering stuff with a new custom SSR frontend using Nuxt, and using WordPress only for CMS edition and storage.
Anyway what I meant with the "PHP can do better things" is that, from an architecture, code design and performance standpoint, PHP can be as modern and performant as any other currently "trendy" system.
Yes I agree with you that WordPress has some shortcomes too. But if you are a php supporter you will definitely know how PhP's older versions were there was a time when people said php is going to be dead in a decade but community made php to make a strong comeback and it has grown gradually, same goes for WordPress it's an open source and has a very supportive community. And if you talk about speed, an efficient developer who understands how WordPress core work's he will write an optimized solution. WordPress itself doesn't create any speed issues its the poorly written plugins that does. Also WordPress Api allows to write custom cache solutions. Currently a lot of work is ongoing to improve WP documentation. Hope to see WordPress succeeds ,adding into PhP's success.
Peace
Thanks for sharing these..please write more from your experience
I can proudly say I'm PHP developer.
🎉 I'm with you on this! 👊
Reason #1 - Laravel, love it! Reason #1 against it would be WP, I'm not touching it with a barge pole ;)
They are very different paradigms. I've heard of people writing beautiful code in WP, but I'm not one of them. Though it did feel magical writing the first theme myself. However, I like following the standard recommendations and Symfony has helped me do that. It's a bit cleaner, and I do like the injection containers!
I have to admit that I have no idea what modern WP code looks like, I worked with it more than 10 years ago and back then it looked like glorified spaghetti code, certainly not like beautiful elegant OOP code. But like I said, I don't know what it looks like these days.
It's like how I first was introduced to PHP. I just wanted a simple website and bought a book that had me hammering out spaghetti. That code is nowhere to be seen today (I HOPE!). And that's kind of the way that WP works too. You could do as much spagetti as you like and easily mutate something that is used on the other side of the project. But you could be sensible with it too! Though I've never been 😉
Yeah for sure PHP has come a long way ...
I mean, old skool PHP was just ugly "script" with as little structure as possible lol ... modern PHP allows you to write beautiful OO code, and it's pretty fast as well - performance of PHP has improved by leaps and bounds since PHP 7 and 8, and stuff like Swoole really puts it in "turbo" mode (and even allows you to do event driven programming if you want) ... types and type checking are being added, I could go on - honestly I think modern PHP is giving Node.js a run for its money ;)
Some nice additions to the language is stuff that we may not even notice. As you say, there's been great preformance boost with 7 and then with 8. JIT is behind the scene doing its thing. Fibers I won't touch but taking advantage of with PHPReact (or maybe framework-x). And yeah, looks pretty swell being a PHP Developer using modern tools right now 😁
It does, modern PHP is powerful and nothing to be ashamed of ;)
Not sure WordPress helps PHP to evolve, ans being popular. I xould Say the exact inverse
Yeah, WP has become huge with the features that was, not the ones that will be. We find other projects driving the evolution now. Send or Laminas was huge, and JetBrains has an interesting relation with the language. But there are so many other projects driving the evolution now. But WP was a major factor of driving many hosting services to support PHP.
I have no hate with wp, i like using it for cheap projects. I agree with you that PHP credibility comes from entities like zend, jetbrain, sensiolabs, php-fig..., who are helping to keep this language to be enterprise usable, and having a huge open source ecosystem (with mature projects like WP).
If WordPress is popular it is because it works on the LAMP stack, and LAMP stack is not popular thanks to WordPress.
Perhaps a bad indicator of being part of the future of PHP, but the WordPress project is not part of the Framework Interop Group (PHP-FIG). This group has given some sensible recommendations and standards we can relate to, and some of these recommendations may not go over so well with WordPress. Just from the standards perspective I could agree with you.
But still... I think WordPress is a huge part of why there are so many websites running on PHP. I've seen WP developers adopting some good standards, but (if I understand you correctly) I agree that it isn't WordPress that is pushing our language forward. As big and somewhat unwieldy the WP project is, I can see how they wouldn't like to see deprecations of features it uses. So, all in all, WP is still a huge part of PHP - but it's not where we look for the next evolution of the language.
I've been doing php since I was 14. I absolutely love the new features in php 8, especially with the propteries in constructors.
I really don't like wordpress personally, I prefer to build stuff myself.
Congrats! I do like modern PHP. Names arguments are neat, and arrow functions, but especially the match control structure!! Wow, does it make for so much more concise code 👏