PHPHolaMundo

De ErlangAr

ejemplo de como comunicar PHP con Erlang, creado por AlvaroVidela usando PHP Erlang Bridge

código PHP:

<?php

$link = peb_connect('hello@127.0.0.1', 'demo');

if(!$link) die ("Can't Connect\n");

$msg = peb_vencode('{~p, ~s}', array(
                                  array($link, $argv[1])
                                 ));

peb_send_byname('hello', $msg, $link);

$message = peb_receive($link);
$rs = peb_vdecode($message);

print_r($rs);

peb_close($link);
?>

código Erlang:

% erl -sname hello -set_cookie demo
-module(hello).
-export([start/0, hello/0]).

start() ->
 MyPid = spawn(hello, hello, []),
 register(hello, MyPid).

hello() ->
 receive
   {Pid, Msg} ->
     Pid ! {self(), welcome},
     io:format("Hello ~s.~n", [Msg]),
     hello();
   quit ->
     ok;
   X ->
     io:fwrite( "Got ~p.~n", [ X ] ),
     hello()
   end.