5 ms·
One of the underappreciated pros of php for web development is its execution model, it's fault tolerant by default and shares little memory across requests. Thi
by aszen 6y ago
One of the underappreciated pros of php for web development is its execution model, it's fault tolerant by default and shares little memory across requests. This kind of makes sloppy programming far more tolerable in php than in other platforms.
In effect this has an impact on performance but it also helps in ensuring that a bad request can't blow out the whole application from serving other requests like is common in platforms like nodejs where you need to be extra careful.
Needless to say this makes php becomes quite viable for production envs, and prevents a whole host of issues that need expertise and careful programming to fix.
- newhouseb 6y agoI'm thankful to have started programming in PHP when I first started doing web work for this reason. Shared mutable state is (almost always) bad and virtually everything I've built after that (on any stack) follows similar rules around per-request isolation because of the patterns PHP instilled in me. Not only does this reduce (1) the likelihood of correctness issues, but it also dramatically reduces (2) deployment complexity because you don't need to migrate a bunch of in-memory state distributed across web backends. Your servers should all be considered dispensable. In 2020, I tend to bias towards things like AWS lambda for this reason (for low volume applications). By default, there's no guarantee on the lifetime of the serving process and any unhandled exception recycles the process so you're never in an unknown (bad) state. There are of course performance downsides to this (particularly when it comes to pooling connections for things like Postgres), but once you figure that out things are generally smooth sailing.
- NationalPark 6y agoPHP apps following modern best practices usually include stateful middleware of some kind though, so this applies in theory more than in practice.
- zapt02 6y agoIf you mean persistent databases or caching like Redis, it's still much easier to accidentally reference a global pointer due to a programming error than accidentally put something in a cache store. All systems need some sort of persistence, this is true for other languages as well.
- NationalPark 6y agoNo, I'm talking about the kind of thing that provides a `Context`-like object that allows the application developer to share memory between requests.
- jozzy-james 6y agothat's not really a thing you do in PHP, outside of frameworks like swoole/roadrunner. by nature it's a fire/execute/die shared-nothing model
- pampa 6y agoyou mean $_SESSION? that was there since at least php4
- mkopinsky 6y agoAnd even that is limited to sharing data for a single user between requests. It's hard to accidentally share data between users.
- zapt02 6y agoLike others have mentioned, there is no such thing in PHP. Each request is handled individually from a blank slate and the context is destroyed when the request finishes.
- wolco2 6y agoWrite to a database or file?
- freeone3000 6y agoThis model is also exceptionally successful in Java Servlet, C# Razor Page, and elixir. And perl CGI. It's possibly more common than not!
- fomine3 6y agoServlet shares instance between request (or you can configure DI container, not so simple), Razor is just a template.
- jrochkind1 6y ago> this has an impact on performance And yet, I find that PHP apps tend to be quite performant, compared to say Java or Rails (I don't know about node, maybe not compared to node). But I'm not a PHP developer, this is just my impression. And the complaints you hear about PHP, I seldom hear performance. No?
- jozzy-james 6y agoif you do something in a naive way, PHP performance can tank pretty severe - but that's more down to the developer implementation rather than a shortcoming of the language itself
- wayvey 6y agoI fully agree, but I think this is an issue in most languages (not counting compiler optimizations)
- acdha 6y agoIt varies considerably. If you write the kind of simple PHP pages which gave it that reputation, it's almost always going to be limited by I/O. If you use a framework which encourages enterprise-style apps with hundreds of includes and object hierarchies which would make a J2EE developer weep, even the opcode cache won't be enough to get back to that spot. I don't follow it enough to see if this passing away niw but there was definitely a sizable chunk of the community which really thought that Real Programmers™ didn't write simple code.
- jozzy-james 6y agoi did a simple test between PHP, Java, Elixir and Haskell for fun (with a full payload/page that represents my problem domain) - PHP was within +/-10ms of the others for the same payload/template process. Guess which one was the slowest?
- mrtksn 6y agoWhat I miss about PHP is that it was possible to put a file in a folder and use it instantly. If you want to quickly do something without diving into frameworks the tooling was easy to setup and rarely fell apart, if ever. There are not many moving parts, you usually have a web server that is very solid and comes with an installer that you hit next next next. Then you have a database server, usually MySQL. Sometimes you would need an extension to work with images, you put it in place by editing an .ini file. Almost like an Excel for backend.
- juangacovas 6y agoThis is still possible, how do you think isn't anymore? As example I mean
- sbarre 6y agoNot OP but I read this as something they miss because they no longer work with PHP.
- mrtksn 6y agoExactly :) Last time I touch PHP I think it was 5, I don’t know what happened in between so when I say “was” I mean it was for me.
- juangacovas 6y agoI see, my mistake!
- jozzy-james 6y agothe largest performance issue i've come across with the execution model is that connection pooling is...well, pretty crap. opcache handles most of the other interpreted woes rather well.
- withinboredom 6y agoAre you talking about connection pooling to services like databases and caches? Most extensions implement it (pgsql and I think MySQL) but you need to configure it. I’ve also use a local nginx proxy to pool the connections.