peb_send_bypid — Send an Erlang message by process ID
peb_send_bypid() send an Erlang message to the Erlang node that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is used.
The process ID on the Erlang node.
An Erlang message term encoded by peb_encode().
The Erlang node connection. If the link identifier is not specified, the last link opened by peb_connect() is assumed.
Returns TRUE on success or FALSE on failure.
Example #1 peb_send_bypid() example
<?php
$link = peb_connect('sadly-desktop@sadly-desktop', 'secret');
if (!$link) {
die('Could not connect: ' . peb_error());
}
$msg = peb_encode('[~p,~a]', array(
array($link,'getinfo')
)
);
//The sender must include a reply address. use ~p to format a link identifier to a valid Erlang pid.
peb_send_byname('pong',$msg,$link);
$message = peb_receive($link);
$rs= peb_decode( $message) ;
print_r($rs);
$serverpid = $rs[0][0];
$message = peb_encode('[~s]', array(
array( 'how are you')
)
);
peb_send_bypid($serverpid,$message,$link);
//just demo for how to use peb_send_bypid
peb_close($link);
?>
pong.erl example code
-module( pong ).
-export( [ start/0, pong/0 ] ).
start() ->
Mypid = spawn( pong, pong, [ ] ),
register( pong, Mypid).
pong() ->
receive
[Pid,getinfo] -> Pid! [self(),welcome],
io:fwrite( "Got ~p.~n", [Pid] ),
pong();
quit -> ok;
X ->
io:fwrite( "Got ~p.~n", [ X ] ),
pong()
end.
will output (on Erlang side):
Got <7160.0.0>. Got ["how are you"].
will output (on php side):
Array ( [0] => Array ( [0] => Resource id #5 [1] => welcome ) )