5 ms·
Judging by comments I saw and what I had my own clients tell me over the phone/mail, it would appear that there's stigma associated with PHP, mostly due to one
by fraktl 7y ago
Judging by comments I saw and what I had my own clients tell me over the phone/mail, it would appear that there's stigma associated with PHP, mostly due to one super-popular blog post called "PHP - a fractal of bad design". I won't go into rebuttal here, the author of the post did enough damage as it is.
PHP evolved significantly since version 4. Version 5 was the "big" deal, with good object oriented features. Version 7 brought the performance in, so we could get rid of Facebook's crappy HHVM (thank you PHP team). Version 8 brings JIT, however most of the workload isn't CPU bound but I/O bound.
So, here's something for PHP devs:
Swoole. http://www.swoole.co.uk http://www.swoole.co.uk -> this is an extension for PHP which brings in the same primitives available to people using Node.js or Golang - coroutines, async I/O, channels, event loop control and much more.
What it essentially does is turn ALL I/O from synchronous to asynchronous. Without any code change or control structure in form of async/await or promises. Write synchronous code, get asynchronous performance.
From my own experience (I've been running swoole in production for 18 months), the performance gain I saw was minimum 500% to a maximum of 2000% (the numbers aren't a joke).
As for PHP - it's a programming language. You can use it right or you can use it badly. This rule applies to almost any language. There's no language in this universe that can turn a bad programmer into semi-ok programmer or even good programmer. If you haven't got the habits and knowledge, there's no language that can rectify it. I've seen way too many people thinking the language of their choice is to blame, but it was always the person in the chair.
PHP performs well. Ecosystem is quite large and luckily there aren't competing standards. Composer, the package manager, is wonderful. There's plenty of frameworks to choose - for web and for CLI usage. Features are being added, slowly but steadily.
I use PHP with Laravel + nginx, next to Nuxt + Vuetify + TypeScript for frontend stuff. Personally, I really like how the mentioned tech can be utilized to create great apps fast - with structured code, that look good and work quick.
Edit: one of the best and most powerful features in PHP (starting with 7.4) is the FFI - foreign function interface. The option to utilize libraries or entire software, without the need to write PHP extensions, is what's amazing for me (I also need it due to nature of my work).
PHP is way more powerful than people give it credit for. But I guess that's what happens when opinions are formed by looking at titles and number of "likes" or other meaningless numbers designed to mislead.
- dana321 7y agoI like the look of swoole, first i've heard of it. There is also a complete application server that supports php servlets, message queue, persistence etc. that is well-supported. Its free, open source. https://appserver.io/ https://appserver.io/ A team that supports Magento, Typo etc. based in Germany wrote it. You can use either the PHP-FPM or the more interesting is the servlets, because the data is kept in-memory - probably much in the same way as swoole functions. Its basically enterprise Java for PHP.
- fraktl 7y agoI know about appserver.io and I would strongly advise against it (I have used it, along with every other project that tried to use pthreads or bypass PHP-FPM). It's not scalable. It also achieves "performance" by having the same process(es) work on the requests over and over again, effectively bypassing what PHP-FPM does on each request. If you set PHP-FPM up that a child process kills itself after 500 requests processed, you'll get the same performance as with appserver, but it'd scale horizontally. It's a toy and I would never use it in production, the authors made a huge mistake of trying to process requests in separate threads - my assumption is they just learned there's a way to expose threads to PHP userland so they toyed with it. Swoole is entirely different beast, it's like comparing a skateboard (appserver) to intergalactic starship (swoole). It's not just about the performance as it is about exposing OS primitives and having fine control over I/O and processes. Excellent find, but luckily - the current tools we've got at our disposal are even better. No offense to people using or working on appserver, some projects are just that - toys that help people learn more.
- dana321 7y agoYeah, looks like an extension to bring a lot of functionality go has into the php space.
- pbowyer 7y agoHave you any view on libev and the PECL ev library? There's been a recent discussion on the php-internals mailing list about whether PHP needs a built-in event based system (https://externals.io/message/108226 https://externals.io/message/108226) . Having input from you with production experience of Swoole would be _fantastic_.