News for hackers. Stuff that matters.
Re:My Favorite Language Has Changed to PHP by kennu on Wednesday March 16, 2022 @11:18AM (#30699855)
The best feature of PHP has always been that it's "serverless", or in more historical terms, stateless. The application itself doesn't have to worry about keeping a server running or making sure it doesn't leak memory or crash. Blast radius is limited to a single HTTP request, just like in AWS Lambda.

The downside is that the PHP service environment does't provide much of a runtime framework, so the PHP application itself needs to perform a huge amount of bootstrapping on every request (this builds up over time as you add stuff to the application). Comparing this to AWS Lambda with e.g. Node.js, Lambda can keep a lot of stuff pre-initialized in memory, and usually just directly execute a handler function. Also things like URL request mapping are externalized to a separate API Gateway. There used to be a lot of tweaking and running separate caching modules needed to make PHP bootstrap fast enough.

I've always been sad that AWS hasn't developed a fully supported PHP backend for Lambda. Combined with a lightweight HTTP gateway, it could be a nice way to keep running legacy apps like WordPress in modern serverless environments, without worrying about server costs and maintenance. You can do it yourself with Lambda layers, but there will be all kinds of small mystery timeouts and problems you have to deal with.

Re:My Favorite Language Has Changed to PHP by marcosdumay on Wednesday March 16, 2022 @02:06PM (#30702030)
When I read comments like this I always wonder who is out there creating stateful HTTP applications?

How does one manage that? How does it not break on every infrastructure change?

In any way, I have never met those people.

Re:My Favorite Language Has Changed to PHP by kcartlidge on Wednesday March 16, 2022 @05:06PM (#30704096)
> When I read comments like this I always wonder who is out there creating stateful HTTP applications?

As a benefit of PHP this isn't a new thing, and usually what is meant isn't that people are deliberately creating stateful HTTP applications (thought they may be!).

What it normally refers to is the way that with PHP every request gets a totally new instance of the interpreter to run in, as it is basically started up from scratch to service that one request, does it's work, then disappears again. There is no possibility of bleed across requests or of accidental shared state.

Whereas with Node, Go, C# etc, there is (by default) a long-lived 'server' process that handles all incoming requests and so doesn't have that automatic request segregation but instead relies on code (framework and/or application).

To rephrase, with PHP there are multiple requests each of which get their own one-shot instance to run in (guaranteeing segregation). With most alternatives there is one server instance which handles multiple requests and something in the stack somewhere has to manage that segregation.

PHP maps many requests to many servers. Versus many requests to one server. But of course this is all very much a simplification.

Re:My Favorite Language Has Changed to PHP by derefr on Thursday March 17, 2022 @12:20AM (#30707638)
Depends on how you define "stateful":

- Are long-lived per-process in-memory read-through caches "stateful"?

- Is per-connected-websocket topic subscription state "stateful"?

In both of these cases, nothing breaks when you hard-kill + restart one of these processes. People who add these things to a web-app backend don't usually think of themselves as making the backend "stateful."

But nevertheless, truly "stateless" technologies like CGI or PHP are defined by how they don't have access to things like this.

Re:My Favorite Language Has Changed to PHP by midrus on Wednesday March 16, 2022 @02:41PM (#30702414)
I think the opposite side of the spectrum in the sense we're talking about "stateless" here would be something like node.js, or Go, where a single "process" is kept alive at all times and responding to every request. In these non-stateless runtimes if you're not careful you could leak information from one request to another, or some unhandled errors or exception terminate not just the request that caused it, but all other request being concurrently handled at the moment the error happens.
Re:My Favorite Language Has Changed to PHP by marcosdumay on Wednesday March 16, 2022 @03:00PM (#30702606)
Ok, I have avoided node and Go. Does their web interface allow your application to share data between instances of your business code? That is a very unusual interface. AFAIK, Java, Python, Ruby, Haskell, and Rust standard servers do not have this on their main interface, and usually require exploiting their cache systems to achieve it (what you can do on Apache too).

Or are you talking about exploring the OS primitives to share data between instances of your code? Because avoiding that shouldn't require a lot of care, and PHP has basically the same capacity.

Re:My Favorite Language Has Changed to PHP by midrus on Wednesday March 16, 2022 @05:07PM (#30704110)
Any runtime that has the concept of "thread locals" or "thread safety" have this sharing problem, no need to exploit y anything. Of those you mention I've worked with Python and java and their runtimes do have this problem (or feature, depending how you look at it). In python for example if you import a module level variable or instance and you modify it's value on a request, you can read it from another request that lands on the same thread. Same with java. I don't know the others you mention but probably are the same as that's how most runtimes work.

You can't do that in PHP, you need to explicitly write to redis/memcached/file/database to be able to read values from another request.

Re:My Favorite Language Has Changed to PHP by mikojan on Thursday March 17, 2022 @04:13AM (#30708754)
For all intents and purposes there is only one instance of your business code. It is a single process. And you do whatever you want.

However, this is not a problem at all. In Go you would have to get out of your way to share information between user agents just like you would have to do in PHP.

Intentionally writing to and reading from a global variable is the exact same as intentionally writing to and reading from your MariaDB instance.

I have no clue why you would render this process problematic. Maybe in Python everything is a global?!

Re:My Favorite Language Has Changed to PHP by kennu on Wednesday March 16, 2022 @02:26PM (#30702269)
At least I wrote a lot of Ruby on Rails and Django (Python) applications back in the day. They always run their own server. I.e. there is no isolation between the server and between the application code.
Re:My Favorite Language Has Changed to PHP by marcosdumay on Wednesday March 16, 2022 @02:49PM (#30702490)
And PHP runs in Apache (or whatever else you use). And an Amazon Lambda runs on their web server.
Re:My Favorite Language Has Changed to PHP by kennu on Wednesday March 16, 2022 @07:47PM (#30705646)
Yes, with Lambda it's Amazon who takes care of the server and you only worry about the application.
Re:My Favorite Language Has Changed to PHP by v0idzer0 on Wednesday March 16, 2022 @08:42PM (#30706104)
Lamda does support php…

https://aws.amazon.com/blogs/compute/introducing-the-new-ser...

Also check out serverless Laravel…

https://vapor.laravel.com/

Re:My Favorite Language Has Changed to PHP by kennu on Thursday March 17, 2022 @10:52AM (#30711818)
Nope, those are guidelines for creating your own PHP runtime for Lambda. It doesn't support PHP natively. The difference is that you need to maintain and debug your own runtime instead of paying for AWS to do it.