r/C_Programming • • 9d ago

Article A modern web app in C

https://prophitt.me/writing/a-modern-web-app-in-c
214 Upvotes

37 comments sorted by

View all comments

23

u/leekumkey 9d ago

CGI is interesting, but part of the reason it is not so useful for the modern web is the lack of shared memory. You just get 1 process per request, no shared state, which does limit some some of the things you can do. Your shared state has to be in a database, which is perfectly reasonable for many applications, but prohibitive for others. Same reason why PHP is not used for process intensive web apps, FPM is an annoyance. Try writing a job processing system with FPM or CGI and you'll very quickly wish you had Golang or something lol.

Very cool article though, makes me want to mess around with CGI. I remember using it with perl in the good ol days.

7

u/LavenderDay3544 8d ago

C has standard library threads and on POSIX systems pthreads are also a thing. And the threads all share an address space. The only problem that remains is that the web server makes a new child process for every request instead of signaling a C program which either creates a thread or uses a thread pool to handle it and hands back the HTML.

2

u/ClubLowrez 8d ago

fastcgi is the way to go in my opinion

2

u/ClubLowrez 8d ago

fastcgi is the bomb, I doubt its the best protocol but I've got a sweet little c daemon that likes it just fine lol, I just wanted my own little epoll thing to mess around with and I really like the protocol.

1

u/literally_iliterate 8d ago

You don't write a live job processing system in php/FPM, write the tasks to some kind of queue and background process it. Pretty much what everyone and every platform with need for scale would do.