使用php连接erlang应用程序

I have a website built with PHP. I have an Erlang application running as a daemon on the same server. I need to call functions on the Erlang application from PHP and get back the result.

I've found PHP/Erlang and over PHP modules but I can't install a PHP module on this server, I can only use PHP code.

The only way I know to solve it is run an Erlang web server locally that the PHP will be able to talk to.

Is there a better way to solve it? If using a httpd server is the best way, what Erlang server should I use? It should be as light as possible and doesn't need features like SSL and doesn't need to handle large load.

Thanks

I don't think there is better solution. I need Erlang webserver to run it on web. here is some info PHP+Erlang related

http://yaws.hyber.org/cgi.yaws

Erlang is excellent at socket I/O: maybe you could use a pipe of some sort?

This would be more direct than through another WEB server layer for sure.

Use the functions erlang:open_port and erlang:port_command functions to get data in/out of Erlang through a system port.

$ cat erl.erl

#!/usr/bin/env escript

main(Args) ->
    io:format("~p
", [Args]),
    io:format("~p
", [(catch test(Args))]).

test([N1,N2|_]) ->
    lists:seq(list_to_integer(N1),list_to_integer(N2)).

$ chmod +x erl.erl

$ cat php.php

?php
var_dump(exec("./erl.erl 1 5"));
?>

$ php php.php

string(11) "[1,2,3,4,5]"

I'd run a webserver such as mochiweb hosting the erlang code. The PHP code would use curl to send http queries encoded in JSON to mochiweb. Mochiweb has a JSON encoder/decoder and PHP has native JSON support.

Even if every thing is on the same server, just use HTTP. Handles all the low level stuff and if you need to scale, it will be easier, as scaling with HTTP is a solved problem. Mochiweb is light and has high performance.

Have a look at erl_call. http://www.erlang.org/doc/man/erl_call.html

It is a unix program which is used to call a function in erlang. It will start a dummy erl node, execute the command(s) and return the result. You could use PHP to call erl_call and then use the results it returns.