News for hackers. Stuff that matters.
Re:The beauty of CGI and simple design by samwillis on Saturday January 07, 2023 @05:33AM (#34286891)
CGI is surprising scalable on modern OSs, the kernel does a good job of caching the code so it's not really a full round trip to the file system on each request. Obviously you still have the overhead of an interpreter for many languages, but they also tend to do a fairly good job of caching their byte code. I absolutely wouldn't recommend it for new systems, but for a quick and dirty script it's fine.

The minute you want to do url routing and have middleware, a persistent process makes everything much simpler and keeps everything in one place. I much prefer routing inside a framework than using Mod_Rewrite.

Re:The beauty of CGI and simple design by geenat on Saturday January 07, 2023 @05:44AM (#34286939)
mod_rewrite hasn't been necessary since nginx.

2023 - Use single binary caddy. It's like 2 lines of config total to remove the extension from your CGI url's.

Re:The beauty of CGI and simple design by samwillis on Saturday January 07, 2023 @05:54AM (#34286986)
Absolutely, and Caddy is brilliant.

My point really was when having url routing, such as ids/slugs in the url, it is much easier to implement in your application code than in the web server configuration. It keeps application code in one place.

Re:The beauty of CGI and simple design by liveoneggs on Saturday January 07, 2023 @07:58AM (#34287628)
What does nginx have to do with mod_rewrite?
Re:The beauty of CGI and simple design by ptx on Saturday January 07, 2023 @09:21AM (#34288174)
nginx hasn't been necessary since mpm_event_module.
Re:The beauty of CGI and simple design by ilyt on Saturday January 07, 2023 @11:26AM (#34289544)
apache haven't been necessary since nginx.
Re:The beauty of CGI and simple design by qbasic_forever on Saturday January 07, 2023 @12:19PM (#34290218)
Caddy doesn't support CGI out of the box. You need to use a module (which requires a custom build of it and the hope the module author continues to maintain it), or you need to run something like fcgiwrap to convert FCGI (what Caddy does support) to CGI (and now you need a process manager to make sure your fcgiwrap and caddy processes are kept running, restarted on failure, etc).
Re:The beauty of CGI and simple design by scotty79 on Saturday January 07, 2023 @06:36AM (#34287169)
> a persistent process makes everything much simpler ...

I started with PHP and never trusted persistent processes for anything.

What if your persistent process hangs or crashes for whatever reason?

Is your whole site down then, not just the part with the bug?

The only site I ever made in persistent process paradigm was in ASP.NET and it didn't cause too many problems but it was more of an app, not website, with limited number of logged in users and pretty much no anonymous/guest part.

Re:The beauty of CGI and simple design by wizzwizz4 on Saturday January 07, 2023 @07:00AM (#34287271)
> What if your persistent process hangs or crashes for whatever reason?

You've got the same problem with your web server, and your operating system kernel. Simply write a program that can't hang or crash – at least, not due to an application bug. It takes attention to detail, but this is a lot easier than writing a program that always behaves correctly; if you limit the syscalls you make, use timeouts appropriately, and don't segfault, it's often achievable.

Re:The beauty of CGI and simple design by scotty79 on Saturday January 07, 2023 @08:27AM (#34287785)
I don't think any mainstream framework in any mainstream language has these kinds of precautions.

Rails? Django? Express? .NET? Do they kill long running requests so they don't affect whole application?

Can the application still mostly work despite syntax error in one of the files?

Another thing is level of trust. I trust Linux kernel, I trust apache webserver. But some webserver written in scripting language few years ago? Not so much.

Re:The beauty of CGI and simple design by Semaphor on Saturday January 07, 2023 @08:39AM (#34287860)
> .NET? Do they kill long running requests so they don't affect whole application?

Not sure about the built-in .net server, but IIS does exactly that. It supports timeout and error/time based restarts for the persistent process.

Re:The beauty of CGI and simple design by alerighi on Saturday January 07, 2023 @02:00PM (#34291358)
Well try in a nodejs server to put a `while(true);` in a request handler. Do you know the answer? The whole process blocks, since nodejs is single process.

I trust more the code that I wrote than the code written from others... not because I'm better than others, but because I know what it does, and I know how to fix it if it breaks.

Re:The beauty of CGI and simple design by scotty79 on Saturday January 07, 2023 @02:18PM (#34291562)
It still wouldn't hurt if the framework just killed it after 3 seconds with timeout message.
Re:The beauty of CGI and simple design by rusebor on Sunday January 08, 2023 @02:32AM (#34296939)
Erlang
Re:The beauty of CGI and simple design by ilyt on Saturday January 07, 2023 @11:25AM (#34289534)
> I started with PHP and never trusted persistent processes for anything.

Well it's (maybe was, it did get a bit nicer over years but old shit code is still there) terrible language so no wonder you have no trust.

> What if your persistent process hangs or crashes for whatever reason?

depend on language. For example in Go (in most frameworks at least) panic() in goroutine handling request will just... nuke that request and nothing else. Sure, memory leaks can be issue if the code is terrible but essentially restarting app after every request is just shitty workaround for shoddy code.

That's how most other handle code. Other, that do multi-core processing badly like Ruby, just spawn multiples of server so it isn't really that different from PHP model, you get "supervisor" that spawns few processes of app and feed them requests, if one dies it just gets restarted.

Re:The beauty of CGI and simple design by wwweston on Sunday January 08, 2023 @11:04AM (#34300191)
> Well it's/twas terrible language so no wonder you have no trust

The reason someone who was shaped by working in PHP probably has less to do with any specific shortcomings of it as a language and more to do with the fact that overwhelming execution model is single-request shared-nothing.

This conceptual model works well enough (especially for the web) there's entire cloud services built around recreating it for other languages called "serverless," and they do well because it's a useful simplification which means the issues associated with persistent processes become somebody else's problem.

Devs being what we are, of course there's always those of us who prefer certain things to remain our problem. This is fortunate as someone needs to assume problems like long-running processes in order for others to make it somebody else's problem. Software development has some things in common with comparative advantage.

Re:The beauty of CGI and simple design by kefka_p on Sunday January 08, 2023 @01:27PM (#34301639)
Fault tolerance was how Next branded it, IIRC. If an instance of a long running process doesn’t communicate with an external monitor, then it’s assumed to have hung or crashed at which point it is restarted by the external tool. Or at least that’s how things were done in the early/mid 90s. Like techniques are employed by Node apps these days, and undoubtedly many others.