DEV Community

Discussion on: All I want for PHP is 🐘

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
 
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
 
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
 
lajeeshk profile image
lajeesh k

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

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.