DEV Community

Anders Björkland
Anders Björkland

Posted on

All I want for PHP is 🐘

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 easy to learn
  • Runs anywhere
  • WordPress!
  • Open Source and free

PHP is just so flexible

It's flexible, fast, and easy to learn. If you know HTML, the next step might be to make it somewhat dynamic. PHP is a great language for that. This leads many newcomers to PHP start coding right away. At first it may be used in a procedural way. For small websites, that's mostly all that is needed. But you can also use it in a more object-oriented way. And guess what, PHP is a great language for that too! But being in the web-sphere of tech, the new rage is functional programming. Does this really have a place in PHP too? This would be a stupid question in an article that is all about the positive sides of what has made PHP popular, right?! Well, it's not. I don't believe in stupid questions. But YES, you can do functional programming in PHP. Also, it runs anywhere.

WordPress is just that huge

Another reason we see so many websites using PHP is that it has been around a long time. From the days of the early Web, PHP was a scripting language that provided basic features that many needed. But now, a major reason for its popularity is the widespread use of WordPress. A Content Management System (CMS) that many (or most of) the hosting services provide has seen WordPress being used by individuals as well as companies such as The New York Times and Forbes. Where a CMS is known to be used, 68% of the time it is a WordPress site.

It's open source and free

It's free and it's open source. This means that it's another licensing fee that many companies just don't have to pay, and there are organizations and individuals investing their time in making it better and more secure. This means that the economical hurdle is super-easy for anyone to get over, and the development of the language is a transparent process. Besides the major features of the language, there are also a ton of extensions ready to be used, such as opcache, xdebug, and many others.

How about you?

What are your thoughts about the popularity of PHP? Why is it so huge? Will it still be popular in 2022? Have you tried PHP, and what do you think of it? Leave a comment below ✍

Further Reading

Top comments (23)

Collapse
 
sobakus profile image
Sobakus • Edited

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.

Collapse
 
andersbjorkland profile image
Anders Björkland

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.

Collapse
 
sobakus profile image
Sobakus

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 :)

Collapse
 
hobbyman profile image
hobbyman

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.

Collapse
 
muhammadfaizanhaidar profile image
Muhammad Faizan Haidar

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?

Collapse
 
sobakus profile image
Sobakus

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.

Thread Thread
 
muhammadfaizanhaidar profile image
Muhammad Faizan Haidar

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

Collapse
 
lajeeshk profile image
lajeesh k

Thanks for sharing these..please write more from your experience

Collapse
 
iambherulal profile image
Bheru lal Gameti

I can proudly say I'm PHP developer.

Collapse
 
andersbjorkland profile image
Anders Björkland

🎉 I'm with you on this! 👊

Collapse
 
leob profile image
leob • Edited

Reason #1 - Laravel, love it! Reason #1 against it would be WP, I'm not touching it with a barge pole ;)

Collapse
 
andersbjorkland profile image
Anders Björkland

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!

Collapse
 
leob profile image
leob

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.

Thread Thread
 
andersbjorkland profile image
Anders Björkland

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 😉

Thread Thread
 
leob profile image
leob • Edited

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 ;)

Thread Thread
 
andersbjorkland profile image
Anders Björkland

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 😁

Thread Thread
 
leob profile image
leob

It does, modern PHP is powerful and nothing to be ashamed of ;)

Collapse
 
fchaussin profile image
François CHAUSSIN

Not sure WordPress helps PHP to evolve, ans being popular. I xould Say the exact inverse

Collapse
 
andersbjorkland profile image
Anders Björkland

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.

Collapse
 
fchaussin profile image
François CHAUSSIN

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.

Collapse
 
andersbjorkland profile image
Anders Björkland

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.

Collapse
 
duncte123 profile image
Duncan

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.

Collapse
 
andersbjorkland profile image
Anders Björkland

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 👏