mongoose/docs/http/cgi.md
Sergey Lyubka 12437fd7fe Refactor Mongoose documentation
PUBLISHED_FROM=e9a4e5c7b4a1d03b93a2a79e29de19e60e919929
2016-09-01 14:35:02 +00:00

1.1 KiB

title
CGI

CGI is a simple mechanism to generate dynamic content. In order to use CGI, call mg_serve_http() function and use .cgi file extension for the CGI files. To be more precise, all files that match cgi_file_pattern setting in the struct mg_serve_http_opts are treated as CGI. If cgi_file_pattern is NULL, **.cgi$|**.php$ is used.

If Mongoose recognises a file as CGI, it executes it, and sends the output back to the client. Therefore, CGI file must be executable. Mongoose honours the shebang line - see http://en.wikipedia.org/wiki/Shebang_(Unix).

For example, if both PHP and Perl CGIs are used, then #!/path/to/php-cgi.exe` and #!/path/to/perl.exe` must be the first lines of the respective CGI scripts.

It is possible to hardcode the path to the CGI interpreter for all CGI scripts and disregard the shebang line. To do that, set the cgi_interpreter setting in the struct mg_serve_http_opts.

NOTE: PHP scripts must use php-cgi.exe as CGI interpreter, not php.exe. Example:

  opts.cgi_interpreter = "C:\\ruby\\ruby.exe";