For the last 15 years or so, my favorite language has been C#, despite using mostly PHP in my workplace since 2012. Over the years, I’ve written a lot of side-projects in C#, and it’s been great, for the most part. Until I learned Assembly… last year.
When I learned Assembly, I think I broke my brain, permanently. New paradigms were learned, old ways to do things were suddenly way too long. I don’t really know how to explain it, but when I came back to C#, suddenly, I felt too constrained.
Like, look at this Merge Sort in C# (130 lines) and then look at it in PHP (31 lines). You can’t beat that kind of productivity, not to mention in PHP, you can even mix data types (like ints and floats) where in the C# version, it’d be much more difficult.
It gets even crazier when you actually benchmark the two languages only to discover in some real-world cases, PHP outperforms C#. Yeah, I know outlandish claims requires substantial proof, but I’m not here to prove to it you. I’m just talking about my reasons for PHP becoming my favorite language (and yes, writing multithreaded PHP is still a PITA).
There are some things I don’t like about PHP, like, the fact that you need two separate processes to serve web pages at scale (nginx + php-fpm). Some of that is solved with Swoole/ReactPHP/AmpPHP and friends, but then you end up needing to rewrite things to work, using special database drivers and things. I’m hoping with PHP Fibers, that’ll be a thing of the past, eventually.
Although, if you’re running something like the nginx ingress in Kubernetes, you can just use the Fastcgi target directly, without an intermediary. That’s actually pretty nice. In this environment, I think it’s actually better than running a native web-server on the pod. There’s no need to parse a forwarded HTTP request (or do http2 to http1 translations), since you’re actually operating on the original HTTP request. Maybe it would be nice if C# provided a Fastcgi binding…
Anyway, I just wanted to announce this to the world because PHP has a bad rap pre-5.3. Since PHP 5.6, things have changed quite a bit. If you haven’t used PHP in the last 7-8 years, you should give it a go.
Comments
2 responses to “My Favorite Language has Changed to PHP”
“It gets even crazier when you actually benchmark the two languages only to discover in some real-world cases, PHP outperforms C#.”
I triple dare you to show code examples so we can explain why you’re wrong.
Quadruple dare
Jesus christ, how did you think this was true
Great post!
People criticize PHP based on their PHP 4.* experience, PHP still having some issues, but it is way better than it was and PHP 8.* performance and “flexibility” is amazing.