by Zak · 1y ago · 0 comments
What does it do better than other languages? The article mentions features that sound like parity with other modern languages, but nothing that stands out.
Shared nothing architecture. If you're using e.g. fastapi you can store some data in memory and that data will be available across requests, like so
import uvicorn, fastapi
app = fastapi.FastAPI()
counter = {"value": 0}
@app.post("/counter/increment")
async def increment_counter():
counter["value"] += 1
return {"counter": counter["value"]}
@app.post("/counter/decrement")
async def decrement_counter():
counter["value"] -= 1
return {"counter": counter["value"]}
@app.get("/counter")
async def get_counter():
return {"counter": counter["value"]}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=9237)
This is often the fastest way to solve your immediate problem, at the cost of making everything harder to reason about. PHP persists nothing between requests, so all data that needs to persist between requests must be explicitly persisted to some specific external data store.Non-php toolchains, of course, offer the same upsides if you hold them right. PHP is harder to hold wrong in this particular way, though, and in my experience the upside of eliminating that class of bug is shockingly large compared to how rarely I naively would have expected to see it in codebases written by experienced devs.
Edit: Oh, you showed an example against Python! Now I get it!
1. Easy deployment - especially on shared hosting 2. Shared nothing between requests means easy concurrency AND parallelism 3. Mixing with HTML means you do not need a separate template language
Not everyone will see the third as an advantage, and many web frameworks, including PHP ones, prefer a separate, more restrictive, template language. It can be a footgun, but it is very convenient sometimes.
While I never actually wanted it, #2 was kinda cool spiritually. Same with CGI or a Cloudflare edge worker.
These days I imagine people are more likely to be using git pull or rsync anyway.
> And php-fpm being called by nginx is also more complicated than just "node script.js" or running a compiled Go binary.
Apache with mod_php is still an option AFAIK. It is also definitely easy to find everything pre-configured on share hosting. Then there is FrankenPHP.
Might not be the easiest option for everyone, but it is going to be for some people.
Like many other things, PHP makes it easier to do the wrong thing than other languages which make you do the same thing correctly.
They switched to blue/green deploys for the new site (which I suspect was done at the server level, not with symlinks or the like).
However, even that doesn't handle in-flight requests that have their view of the files swapped out from under them. Yes, that's a small time window for an error to happen, but it's definitely not instantaneous.
The safer solution would be to update the server config to point at the new directory and reload the webserver, but now you're way past just uploading the new files.
Does that matter if a bit of downtime is acceptable?
Besides the shared nothing architecture mentioned by sibling:
- A more mature community and ecosystem for open source packages e.g. basics like following semver
- One single clear option for package management, which is also by far best in class
- Simply better performance except maybe compared to javascript
While the rest of the options may tick one of the above boxes, none of them ticks all 3.
I still don't think PHP is a good idea for a greenfield project or anything, but they have done a good job of hiding all the footguns.
Agreed. I remember happily starting a couple of new PHP projects in the last decade and the frameworks felt like working in any other programming language.