1, FastCGI Introduction
fastcgi resolves the performance issues caused by the CGI program processing requests to initialize and end each time. FastCGI and is independent of webserver, FastCGI's crash does not affect webserver, and then communicates between them through Soket. Another way to solve a CGI program that is different from fastcgi is to have the Webserver open the API and then write the CGI to embed the CGI into the webserver, so there is a downside that the CGI crash will affect webserver.
There are a lot of servers that support fastcgi, like Nginx IIS or something. They all convert HTTP requests to stdin and some environment variables to the FASTCGI program, and then return to stdout. The final API to write the FASTCGI program is the int fcgi_accept (void), which is returned when a request is delivered.
2, fastcgi installation steps:
Step1:
: HTTP://WWW.FASTCGI.COM/DRUPAL/NODE/5 Click Current:download | Docs | The download link in Browse.
Step2:
TAR-ZXVF fcgi.tar.gz
CD fcgi-2.4.1-snap-0311112127/
./configure–prefix=/etc/fcgi
Make && make install
The fcgio.cpp:50:error: ' EOF ' is not declared in this scope only needs to be added to the/include/fcgio.h file #include
The installation is finished.
3, write and test fcgi program
1) Demo test program fcgi_test2.c as follows:
#include "fcgi_stdio.h" #include <stdlib.h> int Main (void ) {int count = 0 ; while (Fcgi_accept () >= 0 ) {printf ( "content-type:text/html\r\n" "\ r \ n" Span class= "hljs-string" > "<title>fastcgi hello!</title>" " Request number%d running on host <i>%s</i>\n ", ++count, getenv ());} return 0 ;}
2) compiling
[Email protected] cgi-bin]# gcc-g fcgi_test2.c-o fcgi_test2.fcgi-lfcgi
At this point directly run FCGI_TEST2.FCGI will report the following error:
Error while loading shared libraries:libfcgi.so.0:
3) Link Library error Resolution:
Reference: https://www.apachelounge.com/viewtopic.php?p=8160
Program Core-"Link echo with the static library, LIBFCGI.A, instead of the shared library." Linked to a static library, not a shared library.
[Email protected] cgi-bin]# gcc fcgi_test2.c-o fcgi_test2.fcgi-i/etc/fcgi/include/usr/local/lib/libfcgi.a
4) View associated links
[Email protected] cgi-bin]# LDD fcgi_test2.fcgi
Linux-vdso.so.1 = (0x00007fff7fdc3000)
libc.so.6 =/lib64/libc.so.6 (0x00007fa0229ed000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa022d86000)
4, the correct operation results are as follows
1) The program operation results are as follows
[Email protected] cgi-bin]#./fcgi_test2.fcgi
Content-typetext/html<title>FastCGI Hello!</title><h1>FastCGI Hello!</h1>Request number 1 running on host <i>(null)</i>
2) The browser operation results are as follows:
Centos installation fastcgi detailed and use cases