DEV Community

Discussion on: Why does PHP get so much hate?

Collapse
 
andreidascalu profile image
Andrei Dascalu

I've got 17 years of PHP under the belt and there are some points to be said:

  • PHP is a victim of its popularity. With lots of sites across the internet in PHP, there are many old versions there, each bearing significant differences, enough to be a pain to developers migrating between projects
  • Wordpress. Just look at it. Its development is soundly grounded in early php 5 versions. If you have any format programming training, looking at the Wordpress API will leave you wondering if those guys simply hated OOP or any kind of engineering best practices (spoiler: no, but PHP became OOP-ish fairly late for Wordpress to change). Many say that Wordpress is what helped PHP survive enough to become a real language in the later 7.x installments
  • inconsistent API. The core PHP API has always been messy (tons of 'utility' functions thrown around, inconsistent parameters, interfaces you can't implement, etc)
  • it's a web language but ... needs a third-party server to run? That's the biggest pain and WTF for me. At some point PHP got a server as part of its platform, but with a big "don't use in production" sign. Just about any language comes with some webserver implementation as part of its core platform (Java, nodejs, Go, Rust, you name it). Some still recommend using an efficient reverse proxy / balancer (eg: node) but for most others you get it out of the box. PHP has FPM but still can't function without Apache/Nginx. Rubbing salt on the wound: in today's cloud-native world, you can't containerize PHP to simply work with an Nginx ingress or Cloud LB, you still need to package another damn webserver. Ok, nowadays there's a nice multithreaded application platform (Roadrunner) that removes the need for fpm & nginx.
  • the fact that some many radically different versions still live make it difficult to progress as a developer and easy to get trapped in bad code world. Myself as a job candidate keep underlying that I 'support' only PHP >= 7.3, I won't take jobs developing PHP for older versions unless their primary medium-term goal is migration.
Collapse
 
shayneoneill profile image
shayneoneill • Edited

The "needs a third party server" isn't a negative. If theres one bitter lesson to be derived from the rise and fall of Nodejs as a backend webserver, its that servers written in scripting languages will never compete with those written in performant languages like C, Rust or Go. Theres a damn good reason why the rails or django people usually put their stuff behind something like Nginx or Apache. Like yeah, most of these things have native webservers if you want them. But you shouldn't, and nobody with any experience does.

I'm not defending PHP as a language, its atrocious, but it'll flatten any of the JS frameworks for scaleability and performance simply by virtue of the fact it doesn't even try to be a web server.

Collapse
 
andreidascalu profile image
Andrei Dascalu

there's a big different between nodejs's implementation and php. Namely that in a cloud native environment, you can let the ingress controller (effectively nginx or similar) to perform the same task. It will perform the same as on a local machine with an nginx in front of it, since it never needs more than your regular reverse proxy.
FPM doesn't work with that. It needs its own dedicated nginx/apache and doesn't work with pure reverse proxies or load balancer (which are not themselves aware of physically present files).
In this context, while PHP/FPM/Nginx can theoretically scale better on a bare metal environment, it doesn't do as well in a cloud-native environment.

Collapse
 
yellow1912 profile image
yellow1912 • Edited

For server:

  1. You can use PHP-PM to replace PHP-FPM: never tried it, but look very promising (github.com/php-pm/php-pm)
  2. You can implement simple, performance server with Swoole extension (I don't recommend it for normal website, but I created simple tcp/http log servers with Swoole and Clickhouse to record billions of logs per month just fine on a small instance)

Your argument with versions can apply for ALL languages out there. There will ALWAYS be apps that run with code from 10 or 20 years ago. In my experience, the salary for those (boring) jobs taking care of old apps can be way better due to the limited number of capable resources.

Collapse
 
andreidascalu profile image
Andrei Dascalu
  1. You can use php-pm. Like I also mentioned, there's also Roadrunner (slightly better performing than php-pm). PHP-PM has the advantage of working reliably with more PHP versions, but the thing is, PHP is great in newer versions. I'm not bashing on PHP for that, it's a moot point to argue with someone who's seen php 5 code and working with developers who spent years on php 5 and can't bring themselves to 'upgrade' to newer versions and worse -> perpetuate old coding ways.
  2. Sure, Swoole is great, but again, it's one of the modern tools. I really dare you to bring Swoole to Wordpress though.

Well, yeah, but it's only with PHP that you see so much legacy still in production. The only other language with the same weight is Java. It's no to say, for example, that you can't find applications in that are legacy and running, but the special case of PHP is that literally ALL CMS in PHP have their bulk of code written legacy-style. And then people use them to start new applications today and the developers working on them won't be exposed to good practices.

Thread Thread
 
yellow1912 profile image
yellow1912 • Edited

There are modern cms out there, problem is that they don't have enough usage, plugins, and integrations to beat WordPress. That and the fact is that most WordPress users do not care about what's under the hood.

It's kinda unfair to blame the incompetence of the CMS on the language itself though. I think PHP has longer history than some languages and thus have more apps with legacy code. When you have millions of business depend on you, you cannot make radical decision to break things left and right.

Thread Thread
 
andreidascalu profile image
Andrei Dascalu

exactly, so you have an environment the promotes legacy and bad practices. Also, while Wordpress "users" don't care what's under the hood (users or customers never do), Wordpress developers (as in developers customising WP for use cases) also don't (not really). But they have contact in the sense that sooner or later you use hooks, you need to debug - and the code that you see models the code you write. And then the code you write then becomes part of your style. And then, at some point, you come into contact with people who write modern code and .... that builds the reputation of the language.

Thread Thread
 
yellow1912 profile image
yellow1912

Right, I do agree. I have another perspective though, perhaps unique to my situation: when a client contacts you and asks you to do something related to .net or java, they know they must pay big bucks. On the other hand, clients for PHP work normally have a much lower budget, they always look for quick, and cheap gigs. That comes back to bite them in the future though because you cannot have great developers putting a huge amount of care into the project. You end up with quick hacks that are full of holes.

Also despite all it's faults, I find it very difficult to convince a client to try out any other solution. Even knowing all its shortcomings, the clients always want to use something that is popular or recommended by their marketing guy, or that they are familiar with.

I'm not blaming anyone for this of course (perhaps it's everyone's fault?). It's just an observation.

Collapse
 
juslintek profile image
Linas • Edited

Well, now days you can use openlitespeed with its mod_php, a better alternative to php-fpm and nginx or apache mod_php. :-) Also you can use swoole :-) To make it multithreaded and run as a server on its own. As well there are other implementations. As well you can write your own requests handler and run it, for example, like in laravel php artisan serve. There are many solutions, just need to investigate. But yeah something that is implemented to work out of the box for production, yes it doesn't exist. That's why we have web servers. :D

Collapse
 
andreidascalu profile image
Andrei Dascalu

Well, the question was why php gets a bad rep. Think about what you just said. Roadrunner aside, you need to go to third party tools just to get things running.
Nobody ever said there's no way, I also listed some, you did and so on. But there's a lot of legacy out there, lots of inconsistencies in the language and despite all the new stuff that's nice and all, you also need to be in a position to use it.