dongtan3395 2017-06-17 10:52
浏览 157
已采纳

PHP IPC与geth以太坊

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.

Someone hase expirience and be so kind and give me a proper solution?

  • 写回答

1条回答 默认 最新

  • dourang6858 2017-06-17 13:59
    关注

    Update: I found out how it works. I used 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     );
    

    Instead of using MSG Queues I could make it work with simple PHP Socket to the IPC File!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?