4 ms·
> The thing that PHP does right that so few languages do is having a stateless core in the webserver. I never understood why the HN crowd always ignored this m
by spdionis 6y ago
> The thing that PHP does right that so few languages do is having a stateless core in the webserver.
I never understood why the HN crowd always ignored this massive benefit of PHP, in a world where it's becoming clearer everyday that keeping things stateless across the stack provides many benefits towards managing complex systems.
- q3k 6y agoBecause this is not always a benefit. Want to cache something in between requests? You have to use memcached/redis. Want to have some background or periodic processing? Set up cronjobs, and/or use an external job queue system. Sure, if you're writing a simple CRUD app with and RDBMS backend it can be just fine. But when you're dealing with more complex work just being able to start a goroutine or use an in-memory cache structure is so much nicer than having to deal with external systems.
- kstrauser 6y agoMost of the interesting things I’ve worked on would fall down if you couldn’t cache some stuff across requests, like database connections. If every request requires a new TCP connection, even if to something lightweight and fast like a local pgbouncer instance, requests are going to be a lot slower (and the time spent context switching from userspace to kernelspace and back a lot higher) than if you could reuse one from an in-memory pool. I love stateless stuff and have started moving a lot of things to Lambdas where appropriate, but I wouldn’t use a completely stateless setup for handling large numbers of requests per unit time.
- cweagans 6y agoYou can do that in PHP. The PHP database library has a persistent mode that you can use. See the last paragraph of example 3 + example 4 here: https://www.php.net/manual/en/pdo.connections.php https://www.php.net/manual/en/pdo.connections.php
- kstrauser 6y agoSure, but then it's no longer purely stateless, and honestly no more isolated than, say, a Django app (assuming it hasn't been deliberately broken to share state across requests).
- cweagans 6y agoIt's still completely stateless from the dev standpoint (even if it's not truly stateless under the hood). It's more like a caches connection if that makes sense.