PHP IPC with geth Ethereum: How to communicate with client?

0 votes

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.

Oct 22, 2018 in Blockchain by slayer
• 29,270 points
472 views

1 answer to this question.

0 votes

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     );
answered Oct 22, 2018 by Omkar
• 69,000 points

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer

How to connect to *coin RPC-Server with PHP

If you want to connect inside your ...READ MORE

answered Sep 12, 2018 in Blockchain by slayer
• 29,270 points
170 views
0 votes
1 answer

How to connect to already running go ethereum client using mist Ubuntu

Hey, you can solve the issue by using sudo ...READ MORE

answered Sep 18, 2018 in Blockchain by digger
• 26,660 points
71 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,810 points
250 views
0 votes
1 answer
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,620 points
213 views
0 votes
2 answers

How to generate ethereum qr code address with amount?

You implement this package: ethereum-qr-code. It implements the EIP67 standard which uses ...READ MORE

answered Sep 6, 2018 in Blockchain by Omkar
• 69,000 points
869 views
0 votes
1 answer

How to reintialize genesis block in geth ethereum?

You are getting this error because you ...READ MORE

answered Dec 5, 2018 in Blockchain by Omkar
• 69,000 points
975 views