PHP IPC with geth E...
 
Notifications
Clear all

PHP IPC with geth Ethereum How to communicate with client  

  RSS

Ganesh A
(@ganesh)
Noble Member
Joined: 4 months ago
Posts: 1170
30/03/2021 11:38 am  

I have setup geth Ether testnet. I want to communicate over IPC PHP with the client. Im on Ubuntu. This is my current code:

$myValType = NULL;
$msg = "";
($key = ftok("/home/john/.ethereum/testnet/geth.ipc","="));
$queue = msg_get_queue($key);
msg_send($queue, 1, '{"jsonrpc":"2.0","method":"miner_start","params":[],"id":1}');
msg_receive($queue,0,$myValType,2048,$msg);
dd($msg); # (Die and Dump, Laravel)

This is the IPC File(FIFO?):

srwxrwxrwx 1 john john    0 Jun 17 01:30 geth.ipc=

This is working fine

echo '{"jsonrpc":"2.0","method":"rpc_modules","params":[],"id":1}' | nc -U geth.ipc

I'm not sure how to actually communicate with the client. There is no response from it when sending. On msg_receive it just returns the initial sent message.

 

Quote
Anamika
(@anamika)
Noble Member
Joined: 4 months ago
Posts: 1179
30/03/2021 11:39 am  

You have to use PHP Sockets

$sock = socket_create(AF_UNIX, SOCK_STREAM, 0);
socket_connect($sock, "/home/john/.ethereum/testnet/geth.ipc",1);
$myBuf = null;
$msg = "{\"jsonrpc\":\"2.0\",\"method\":\"rpc_modules\",\"params\":[],\"id\":1}";
socket_send($sock, $msg, strlen($msg), MSG_EOF);
socket_recv ( $sock , $myBuf ,  100 ,MSG_WAITALL     );

ReplyQuote
Share: