Skip to content

Using FastCGI protocol

Roman edited this page Apr 24, 2017 · 4 revisions

Using FastCGI protocol

About this protocol you can read more in wiki.

This protocol implement genserver which allows for independence from general app.

First step

Start new fcgi process and start connection with fcgi server

{ok, Pid} = sgi_fcgi:start(1,1), % (FCGI_RESPONDER, FCGI_KEEP_CONN)

We keep pid of process for avoiding copy of data using methods. After this function we keep also connection process.

Send request or data

Easy and fast way to send request.

It icludes list of CGI params and POST pody if exists.

Pid ! {overall, self(), CGIParams, has_body(Http), Body},

Other way to send request if you need more flexibility.

But this way slowly than above.

Send Params to server as a pair {Key,Value}

sgi_fcgi:params(Pid, FCGIParams),

Send POST data to a server, using real Pid so without excessive copying

Pid ! {5, Body},

Send the marker that the request is ended

sgi_fcgi:end_req(Pid),

Receive

Receive message from server with next tags.

{sgi_fcgi_return, Out, Err} % common respones
sgi_fcgi_return_end % end of the requet, we can retun the answer to a browser
{sgi_fcgi_return_error, Err} % some error
{sgi_fcgi_timeout, Pid} % self timeout

Last step

Stop fcgi process with the release of resources. Connection process let go also, of course, if you don't use Multilexer, in that case connection leave after first step.

sgi_fcgi:stop(Pid),