FastCGI

term

web dev

Kept in this browser · My desk

A binary protocol between a web server and long-lived application processes, specified by Open Market in 1996 as an open extension to CGI.

Where CGI starts a process for every request, a FastCGI application keeps running and accepts connections on a listening socket. Each request travels as typed records over that connection: parameters, request body, output and errors in separate streams. PHP-FPM speaks it; NGINX speaks it through fastcgi_pass and Apache httpd through mod_proxy_fcgi.

Mark R. Brown's specification, version 1.0 of 29 April 1996, defines an eight-byte record header (version, type, request ID, a content length of up to 65,535 bytes, a padding length) and eleven record types, from FCGI_BEGIN_REQUEST and FCGI_PARAMS to FCGI_STDOUT and FCGI_END_REQUEST. The request ID lets one connection carry several requests, and the FCGI_KEEP_CONN flag decides whether the application closes the connection after answering or leaves it to the web server.

Applications play roles: Responder, the CGI-like role PHP plays, Authorizer and Filter. fastcgi.com, where the specification was published, is offline, and the text survives in the community FastCGI Archives. Because the parameters a web server sends can carry PHP settings, an exposed FastCGI port is a route to running code, which is why the PHP manual insists that php-fpm stay off untrusted networks.

Also known as: fcgi, fast cgi, fastcgi protocol, fcgi_keep_conn, mod_proxy_fcgi, fastcgi_pass

← Back to F Back to the glossary