Skip to content

A small and simple FastCGI client written in Erlang

License

Notifications You must be signed in to change notification settings

mbihoop/erl_fastcgi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

erl_fastcgi

A small and simple FastCGI client written in Erlang.

Build

make

Installing

In your Rebar project:

{deps, [
  {erl_fastcgi, {git, "git://github.com/marcelog/erl_fastcgi", {ref, "master"}}}
]}.

Use example

test() ->
  Host = "127.0.0.1",
  Port = 9000,
  TryToReconnectEveryMillis = 1000,

  {ok, FastCGIConnection} = erl_fastcgi:start_link(
    Host, Port, TryToReconnectEveryMillis
  ),

  ARandomRequestId = 600,
  Body = <<"a=1&b=2">>,
  erl_fastcgi:run(FastCGIConnection, ARandomRequestId, [
    {"SCRIPT_FILENAME", "/tmp/test2.php"},
    {"QUERY_STRING", "a=1&b=2"},
    {"REQUEST_METHOD", "POST"},
    {"CONTENT_TYPE", "application/x-www-form-urlencoded"},
    {"HTTP_CONTENT_TYPE", "application/x-www-form-urlencoded"},
    {"CONTENT_LENGTH", integer_to_list(size(Body))},
    {"HTTP_CONTENT_LENGTH", integer_to_list(size(Body))},
    {"SCRIPT_NAME", "test2.php"},
    {"GATEWAY_INTERFACE", "CGI/1.1"},
    {"REMOTE_ADDR", "1.1.1.1"},
    {"SERVER_PROTOCOL", "HTTP/1.1"},
    {"REMOTE_PORT", "1111"},
    {"SERVER_ADDR", "127.0.0.1"},
    {"SERVER_PORT", "3838"},
    {"SERVER_NAME", "host.com"}
  ], <<>>),

  test_wait(FastCGIConnection).

test_wait(FastCGIConnection) ->
  receive
    {fast_cgi_done, _} -> ok;
    X ->
      io:format("Got: ~p~n", [X]),
      test_wait(FastCGIConnection)
  after
    5000 -> erl_fastcgi:close(FastCGIConnection)
  end.

Your process should get messages like these:

{fast_cgi_stdout,600,<<"X-Powered-By: PHP/5.6.30\r\nContent-type: text/html; charset=UTF-8\r\n\r\n">>}
{fast_cgi_stdout,600,<<"<html>">>}
{fast_cgi_stdout,600,<<"</html>">>}
{fast_cgi_done,600}
{fastcgi_request_done,600,fast_cgi_connection_reset}

Pooling

There is no pooling support out of the box, but you can use your favorite worker pool library to run as many of these as needed.

Related reads

License

The source code is released under Apache 2 License.

Check LICENSE file for more information.

About

A small and simple FastCGI client written in Erlang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Erlang 98.0%
  • Makefile 2.0%