News for hackers. Stuff that matters.
Re:What's new in PHP 8? by mjw_byrne on Friday August 14, 2020 @06:02AM (#24155947)
I used to use PHP as a web backend and then moved to Go. Forgetting the debate about the actual languages, it makes so much more sense to me for a web app to be a full-fledged, self-contained program which happens to listen on a network interface and respond when things make HTTP requests at it.

The old-school style, where routes map to scripts or parts of scripts and a separate web server like Apache or Nginx sits in front of the app, feels harder to reason about (does this thing persist across requests?), harder to debug (where did that error message end up?) more brittle (did this fail because of my script or my web server config or something else?) and more dependent on configuration magic (i.e. various text files lying around governing the behaviour of things).

So although some of these changes look cool, I don't think it's the language itself that most needs improving.

Re:What's new in PHP 8? by sergiosgc on Friday August 14, 2020 @06:22AM (#24156086)
Funny. I completely disagree, and actually find it odd someone actually wants desktop style application state on web apps. One of the beauties of the PHP style of app execution is that application state is a lot simpler. Instead of having a running application server-side, which can be in a continuum of states, PHP forces you to start every request with a blank slate. Application state must be explicit (with serialized server-side sessions or browser-stored cookies). This makes it trivial to reproduce requests, trivial to debug, trivial to scale horizontally.

To each his own, I guess. I just find your position genuinely surprising.

Re:What's new in PHP 8? by zapt02 on Friday August 14, 2020 @08:19AM (#24156901)
By starting every request from a clean slate, you have much less mental overhead (did I accidentally reuse a variable from a previous request?) and it eliminates an entire class of programming bugs. It's the best thing about PHP, and despite this approach PHP still runs faster than many similar languages.
Re:What's new in PHP 8? by mjw_byrne on Friday August 14, 2020 @09:50AM (#24157895)
I think the "clean slate" benefit is achievable almost for free in a monolith though - each request is a separate invocation of a handler function which is given the context it needs to run (e.g. an HTTP request, an output stream and user-defined context).

The user-defined context is the only route into the application state and can be as wide or narrow as you need. So you can share persistent state deliberately, e.g. by having that context contain a pointer to a db conn, but this is always a conscious, opt-in choice, and errors like accidental reuse should be impossible unless you're doing something inadvisable like using global variables.

Re:What's new in PHP 8? by fetbaffe on Friday August 14, 2020 @10:15AM (#24158231)
After doing Java Spring I realized that the Java monolith was very leaky and inflexible. That is why you have strong trend of micro services.

In 99.9% of cases in web development you want the PHP model of doing things. The 0.1% case is the asynchronous background job, that can be solved, maybe not as elegant as in other languages, but why optimize the edge case?

Re:What's new in PHP 8? by jjeaff on Friday August 14, 2020 @02:41PM (#24161639)
My backend is written in php and I simply have a separate container running a copy of the same php codebase that has a long running process pulling from a pubsub queue in a loop.

So anything that needs to be processed asynchronously, like say, sending out a few dozen emails or notifications, I just publish the task to the queue and that other container handles them.

This could be simplified even further if you use a pubsub service that can post data to a url as it comes in. Thus allowing the single php container to asynchronously process the tasks all in their own individual threads.

This didn't work for me as Google cloud's pubsub seems to absolutely flood it's target with requests seemingly ignoring 503 or any other error code and not backing off until it has dos'ed your server.

Re:What's new in PHP 8? by lolinder on Friday August 14, 2020 @04:07PM (#24162634)
The problem lies in your last point. Any PHP+Apache app, no matter how bad the programming practices, has the property that every request gets a blank slate except for explicit database connection. In most other stacks it is way too easy to add a singleton class or a global variable and break that guarantee.

That said, I'll gladly take the guarantees of a type checker in exchange for giving up the guarantees of statelessness. It would be nice if there were a stack that could give me both.

Re:What's new in PHP 8? by mjw_byrne on Friday August 14, 2020 @09:22AM (#24157590)
I think it comes down to how we assess the cost of things. To me, the issues you identified with state (which I agree are real issues) are straightforward to overcome with disciplined design. On the other hand, I find not having application-wide state to be a handicap - e.g. I might want to have my application process batch jobs asynchronously or share state between requests in a highly efficient (read: in-memory) way.

Of course there are solutions in PHP-land, e.g. "run a job server" or "use Redis", but I find the overall cost of introducing more programs/services/components to be very high, in terms of learning curve, portability, maintenance and debugging.

I've spent the last few years replacing a crumbly, brittle, temperamental PHP/nodejs/Gearman/Redis/Nginx/Supervisor stack with a Go monolith so I'm sure that influences my opinion :-)

Re:What's new in PHP 8? by jjeaff on Friday August 14, 2020 @02:43PM (#24161673)
Does that mean you had to re-invent the wheel with your go monolith for a lot of things?

My understanding is that the go philosophy is very package independent and the availability of existing code to solve common problems is rather sparse.

Re:What's new in PHP 8? by waheoo on Friday August 14, 2020 @06:08AM (#24155999)
Interesting take.

I don't really agree, php routes are handled natively and very simply and easy to reason about using the .php extension.

Its the frameworkers that broke that design with clean urls and fancy complicated routers.

Php behind Apache or nginx is incredibly simple and easy to reason about.

Browser loooks up this file url, this file url runs as a script and its output is returned.

A bug in one file isn't propogated to all others so you can have highly reliable services with only partial failures from time to time.

Whereas a bug in one route of a golang server may take the entire service offline.

I do much prefer the deployment and shipability of a golang service, so much I am willing to give up the simplicity of PHP.

Re:What's new in PHP 8? by clon on Friday August 14, 2020 @07:36AM (#24156573)
Absolutely, having a service that just listens on port 80 is so much simpler to reason about. I would also add a much easier development setup, as well as deployment to your list of advantages.

That said, having a Go service just be exposed to the wild wild internet may not be a smart idea. Take a look at this issue [1], it is perfectly clear that Go services (relying on net/http) still need babysitting by a competent reverse proxy. It is a case where Go's mantra about simplicity leads to leaky abstractions and just clearly immature solutions.

Also not talking about TLS certs, WAF and other concerns that also may bring nginx etc on board anyhow.

[1] https://github.com/golang/go/issues/16100

Re:What's new in PHP 8? by eggsnbacon1 on Friday August 14, 2020 @08:31AM (#24157027)
Lol I remember seeing this timeout issue years ago and immediately deciding I would never use Go for HTTP (which is what it was designed for). This makes Go vulnerable to numerous slow attacks and there's no way around it besides "use a proxy".

My guess as to why this issue is left open? Google has global timeouts set on all the network edges so they don't want each service to use its own. Whats good for Google overrides whats good for the supposedly open source project.

This is pervasive in most of their projects. Google open source is like the Reapers from Mass Effect series. They leave some crumbs behind to ensure the software ecosystem develops along desired paths. Not out of charity, they do it to ensure a successful harvest.

Re:What's new in PHP 8? by clon on Friday August 14, 2020 @08:40AM (#24157105)
This timeout issue is indeed baffling. I believe many Go services out there may have set their timeouts to something ridiculous like 3600 or 86400 as a "fix". Hello slow lori.

Another concern is that the lifetime of a PHP app is rather short, measured in milliseconds. This is actually a rather robust approach. Crashes, memory leaks, all sort of weird states are brushed away immediately to be replaced with fresh state for the next request. Apache/nginx is acting as a supervisor and allowing a lot of shit code live out it's days unnoticed.

Contrast that with long-running Golang processes. You won't get away with sloppy code there, raising he bar considerably. Running a Go executable without a monitoring supervisor is sketchy at best.

Re:What's new in PHP 8? by eggsnbacon1 on Friday August 14, 2020 @08:51AM (#24157199)
I'll be honest, I'm pretty anti-Go. Its filled with hacky workarounds for when various things don't fit their "simple" abstractions. File IO and paths is laughably not cross-platform because of this, for example.

Networking is another example. And casting to interface while the built-in collections secretly use generics.

A good way to avoid all these problems is to use a language with great cross-platform support like Java or C#.

Re:What's new in PHP 8? by fetbaffe on Friday August 14, 2020 @06:35AM (#24156162)
Personally I think that separating the application from the web server is good thing, but I do agree that this is the part that can give you the most trouble.

Running a PHP project isn’t as easy as

  git clone
  make run
because of the web server. Difficult to configure, hard to share configurations between machines, differences between operating systems (and Linux distributions) where to put configurations, different ways to hook into php.

Projects starting to rely on specific web server configurations for different application behavior, e.g. htaccess files.

Hard to debug when you need to special request handling like terminating the request but continue executing or continuously stream data (web server response cache).

I guess that is the price you pay for separating the application from the web server.

Re:What's new in PHP 8? by AegirLeet on Friday August 14, 2020 @09:22AM (#24157589)
The old-school style you describe is indeed old-school and was abandoned by most PHP developers ~10 years ago.

Modern PHP projects will have a single entry point that handles all requests, with path-based routing done in code.

Re:What's new in PHP 8? by jrururufuf666 on Friday August 14, 2020 @10:22AM (#24158308)
in cheap shared hosting apache setups its still the best way to do 7t oldschool. still love it
Re:What's new in PHP 8? by stephenr on Friday August 14, 2020 @08:19PM (#24164780)
Shared nothing is a huge benefit in simplicity.

“Does this thing persist across requests” is ridiculously simple to answer in php because the answer is “no, unless you very explicitly told it to”.

In a go or java or whatever service you have to know if your “thing” is specific to the request handler, or if it’s part of shared state.

There is no reason that routing in a php app has to be done via mapping urls to php files, it’s a very common practice to have a front controller that bootstraps the app environment and in turn handles routing of the request to a piece of logic.

Re:What's new in PHP 8? by dingdingdang on Friday August 14, 2020 @09:37AM (#24157750)
I know this replicates the sentiment expressed by other in this thread but still: Go does not do away with the need for front end servers for deployed end products.

And so the eventual proxying Go behind Nginx or Apache comes with it's own cost since Go is nowhere near as tested as PHP when it comes to server integration.

Re:What's new in PHP 8? by golergka on Friday August 14, 2020 @08:52AM (#24157219)
> web app

I think that this vague definition, right here, is the source of disagreement. Are we talking about small blog with comments?

Or are we talking about one of the services of a medium-sized company, that needs to provide a platform-agnostic API, and real-time updates to subscribed clients with websockets?

Re:What's new in PHP 8? by mjw_byrne on Friday August 14, 2020 @09:27AM (#24157634)
Yeah, in my case I'm talking about a thing that is largely a web app but also does other things which don't fit well into the one-script-execution-per-request model.

That being said, I would still prefer a monolithic application for a small blog with comments because I think it's easier to manage, deploy, encapsulate, test etc.