Calling a CGI script is pretty simple. PHP has several features, but you basically need to set up a list of environment variables, and then call the PHP-CGI binary:
setenv GATEWAY_INTERFACE="CGI/1.1" setenv SCRIPT_FILENAME=/path/to/script.php setenv QUERY_STRING="id=123&name=title&parm=333" setenv REQUEST_METHOD="GET" ... exec /usr/bin/php-cgi
Most of them are templates. SCRIPT_FILENAME is how to pass the actual php file name to the PHP interpreter, and not as the exec parameter. Also decisive for PHP is the non-standard variable REDIRECT_STATUS=200 .
For a GET request, you only need environment variables. For a POST request, you simply pass the body of the HTTP request as stdin to the php-cgi binary executable. The returned stdout is a CGI response consisting of an incomplete HTTP header, \ r \ n \ r \ n, and the body of the page.
(Only from memory. Perhaps a few more errors).
source share