How is FastCGI in C?

I have a website on which each web page is compiled into a binary file (I have 100 web pages, so I have 100 binary files). Apache.htaccess contains the string “SetHandler cgi-script”, which instructs apache to use CGI when it requests a binary (web page).

How can I change this site to use FastCGI instead of CGI?

Do you just need to include this header and use this while loop ( FastCGI.com ) in each of the 100 binaries and change the .htaccess to "SetHandler fastcgi- script"?

#include "fcgi_stdio.h" // instead of stdio.h  
while(FCGI_Accept() >= 0)  

So how will FastCGI work? Will Apache send web pages using 1 persistent process for the entire website, or will there be 1 persistent process for each of the 100 binaries?

+3
source share
1 answer

FastCGI script is a network server that listens for connections in a loop. The web server sends requests to the FCGI server, which sends back dynamically generated content - across the socket connection. Thus, the FCGI script is faster than the CGI, as it is not re-created for every request.

, 100 100 . script 100 . FCGI , . ( , ).

100 , 100 if. :

hash_table page_generators; // map page types to function objects (or function pointers)
page_generators["login_page"] = handle_login_page_fn; 
page_generators["contact_page"] = handle_contact_page_fn; 
// ... and so on

// request handler
page_type = request.get("page_type");
fn = page_generators[page_type];
if (fn == NULL)
    return "<html><body>Invalid request</body></html>";
else
    return fn(request);
+1

Source: https://habr.com/ru/post/1773394/


All Articles