peb_send_bypid

peb_send_bypidSend an Erlang message by process ID

Description

bool peb_send_bypid ( resource $process_id , resource $message_identifier ,[ resource $link_identifier ] )

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.

Parameters

process_id

The process ID on the Erlang node.

message_identifier

An Erlang message term encoded by peb_encode().

link_identifier

The Erlang node connection. If the link identifier is not specified, the last link opened by peb_connect() is assumed.

Return Values

Returns TRUE on success or FALSE on failure.

Examples

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);
$rspeb_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
        )

)

See Also