this post was submitted on 04 Jan 2024
113 points (95.9% liked)

Programming

16760 readers
228 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 7 months ago (3 children)

Each request is a totally independent request that rebuilds the world. There’s no shared state (unless you want there to be).

I with there was a language with this model, but without the language itself being completely garbage.

[–] [email protected] 6 points 7 months ago

Isn't that the same as modern languages? For example in ASPCore / C#, you can just register all your services with a lifetime scoped to the request, and then there's no shared state.

If you want there to be a shared state, you'd just have to register your services with a higher lifetime scope, like with a singleton scope

[–] [email protected] 4 points 7 months ago* (last edited 7 months ago) (1 children)

You can still use CGI with Apache. Apache will execute your program on each request and return its output from stdout as webserver response. If you have a form, it'll get POSTed to stdin when Apache execute your program. You can write your program with whatever language you want as long as you can read stdin and write to stdout. It's just tedious af so no one really use it these days. PHP was basically born because people got tired writing CGI program with pearl or C and want something more convenient. But with modern programming languages, perhaps CGI is not too bad, except the one process per request which will absolutely kill your server the moment you have visitors spike.

[–] [email protected] 1 points 7 months ago (1 children)

You can still use CGI with Apache. Apache will execute your program on each request and return its output from stdout as webserver response. If you have a form, it’ll get POSTed to stdin when Apache execute your program. You can write your program with whatever language you want as long as you can read stdin and write to stdout. It’s just tedious af so no one really use it these days.

You can't use the CGI model with node and JS/Node because... unlike PHP, the thing isn't designed for a quick start and shutdown.

[–] [email protected] 1 points 7 months ago (1 children)

Why not? Is it because a typical nodejs app include hundreds of npm dependencies? As long as it can launch and finish within 60s (default timeout for apache), you should be able to use it.

[–] [email protected] 2 points 7 months ago (1 children)

Who wants to wait 60s for a website to load?

[–] [email protected] 1 points 7 months ago (1 children)

Not saying you should use CGI (who does these days), but saying you could still use it if you want

[–] [email protected] 1 points 7 months ago

The point is that PHP is much more performant and doesn't waste resources as NodeJS does. While you can run PHP on CGI with a decent bootstrap performance that won't get people annoyed the same can't be said of NodeJS. Nowadays people do PHP-FPM which is way faster at scaling up that any NodeJS process manager out there and doesn't sit wasting resources when a particular application doesn't have requests.

[–] [email protected] 3 points 7 months ago

And there is... its called PHP. JS doesn't have this model because it is complete garbage slow and wouldn't ever run fine and reasonable in that model.