Last active
October 13, 2017 20:25
-
-
Save marcelog/287bc17d9f1bc8c59862083bf0de6f60 to your computer and use it in GitHub Desktop.
Calling a FastCGI application from Erlang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test() -> | |
Host = "127.0.0.1", | |
Port = 9000, | |
TryToReconnectEveryMillis = 1000, | |
% Start a persistant FastCGI connection to the application server | |
{ok, FastCGIConnection} = erl_fastcgi:start_link( | |
Host, Port, TryToReconnectEveryMillis | |
), | |
% We need to provide the request IDs, and the FastCGI | |
% parameters needed to run the request | |
ARandomRequestId = 600, | |
PayloadData = <<>>, | |
erl_fastcgi:run(FastCGIConnection, ARandomRequestId, [ | |
{"SCRIPT_FILENAME", "/tmp/test.php"}, | |
{"QUERY_STRING", ""}, | |
{"REQUEST_METHOD", "GET"}, | |
{"CONTENT_TYPE", "text/html"}, | |
{"CONTENT_LENGTH", "0"}, | |
{"SCRIPT_NAME", "test.php"}, | |
{"GATEWAY_INTERFACE", "CGI/1.1"}, | |
{"REMOTE_ADDR", "1.1.1.1"}, | |
{"REMOTE_PORT", "1111"}, | |
{"SERVER_ADDR", "127.0.0.1"}, | |
{"SERVER_PORT", "3838"}, | |
{"SERVER_NAME", "host.com"} | |
], PayloadData), | |
% Now let's wait for the app server to tell us how | |
% that worked! | |
test_wait(Pid). | |
test_wait(Pid) -> | |
receive | |
X -> | |
io:format("Got: ~p~n", [X]), | |
test_wait(Pid) | |
after | |
5000 -> close(Pid) | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment