erl_fastcgi

其他类别 2025-08-19

erl_fastcgi

用Erlang编写的小型快速餐饮客户端。

建造

make

安装

在您的钢筋项目中:

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

使用示例

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.">
 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 .

您的过程应该收到这样的消息:

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

合并

可以开箱即用的汇总支持,但是您可以使用自己喜欢的工作池库根据需要运行尽可能多的其中。

相关读取

  • 从Erlang致电FastCGI应用程序
  • 使用FastCGI使用Erlang和Cowboy服务PHP应用程序

执照

源代码在Apache 2许可下发布。

检查许可证文件以获取更多信息。

下载源码

通过命令行克隆项目:

git clone https://github.com/marcelog/erl_fastcgi.git