Most active commenters
  • ksenzee(3)

←back to thread

123 points jonfelsar | 18 comments | | HN request time: 0.754s | source | bottom
1. dingdingdang ◴[] No.45189044[source]
The point made in the article:

* resource leaks are non-existent

Can not be emphasized enough imo. The amount of absolute ridiculous levels of pain instigated by expecting a core code loop to run -forever- and doing so well while being written for some web project or other is just too much to fathom. Just use PHP and serve the request. Then let it die. Then serve a new request.

replies(7): >>45189095 #>>45189147 #>>45189280 #>>45189375 #>>45189453 #>>45189777 #>>45194297 #
2. ksenzee ◴[] No.45189095[source]
This is, indeed, my favorite feature of the language.
replies(1): >>45189251 #
3. mekazu ◴[] No.45189147[source]
Agree that it’s good to get the certainty of zero memory leaks (assuming there’s no associated bugs in apache) but it’s not that hard to write code that doesn’t cause memory leaks for stateful apps as long as you are able to follow certain simple principles and avoid bugs in the third party libs you use.
4. nine_k ◴[] No.45189251[source]
It's not a language feature but a runtime feature. There's no reason why JS or Python or Java could not be run like that.
replies(1): >>45189288 #
5. nedt ◴[] No.45189280[source]
It‘s called „shared nothing“. Also makes scaling easier and you can restart processes anytime without impact, because every request starts at zero anyway.
6. ksenzee ◴[] No.45189288{3}[source]
The language itself, though, does absolutely have this assumption built in. If you want to run it in an endless loop, you’ll have issues.
replies(1): >>45189702 #
7. donatj ◴[] No.45189375[source]
It also makes scaling across multiple servers an absolute breeze when there's no shared state across requests to worry about.
8. majorbugger ◴[] No.45189453[source]
This has got to be a joke.

What if you need any kind of in-memory cache? Or in general, any kind of application maintaining state, for, say, performance reasons?

replies(1): >>45189689 #
9. EGreg ◴[] No.45189689[source]
PHP has apcu as the in-memory cache

And it’s not a joke, PHP is actually the most secure runtime environment out there for web hosting, PRECISELY because of the shared-nothing architecture.

Faster runtimes exist, like Swoole and recently FrankenPHP, to do evented programming like Node JS. But let me tell ya — you risk all kinds of leaks, both of unfreed memory and of secrets, across requests. It ain’t worth it most of the time!

10. EGreg ◴[] No.45189702{4}[source]
No you won’t, other runtimes like Swoole, FrankenPHP, and even amphp let you do that, just spin up a PHP process.

I wouldn’t recommend them, though.

replies(2): >>45189996 #>>45195465 #
11. frizlab ◴[] No.45189777[source]
Where I worked we had to reboot the php-fpm servers periodically because they had a leak…
replies(1): >>45189851 #
12. hu3 ◴[] No.45189851[source]
There's a configuration to cycle php-fpm workers every X requests:

https://www.php.net/manual/en/install.fpm.configuration.php#...

replies(1): >>45189956 #
13. frizlab ◴[] No.45189956{3}[source]
Good to know!
14. ksenzee ◴[] No.45189996{5}[source]
“You’ll have issues” was my way of saying “I wouldn’t recommend them.” IMO if you want to run in a loop, pick a language where that’s the standard practice.
15. johntash ◴[] No.45194297[source]
One of my biggest issues with php was the number of imports and file reads involved. It made running something like wordpress _really_ slow on slow disks or over nfs. I don't remember apcu or opcache helping much for that because I think it still did a stat on every file iirc.

For single-file php apps or just not using a big framework, it's not really a problem.

replies(1): >>45194529 #
16. spdionis ◴[] No.45194529[source]
You can configure opcache to never stat unless it's reloaded
replies(1): >>45202933 #
17. dingdingdang ◴[] No.45195465{5}[source]
I find some of the language around FrankenPHP difficult to parse - is FrankenPHP always in loop mode (ala ReactPHP) or is it simply an option? I can't tell.. my gut reaction upon reading the intro material is that they "simply" replaced Apache/Nginx with Go's inbuilt, and much lighter, server structure and that PHP itself is left to run completely isolated as per usual?!

edit: indeed https://frankenphp.dev/docs/classic/ indicates normal runner capability similar to Apache.

18. johntash ◴[] No.45202933{3}[source]
Huh, well that sounds like it would have been useful. It's been at least 10 years since I did any php dev work, but maybe I'll find an excuse to use it again for something.