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

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!

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

报告相同问题?

悬赏问题

  • ¥20 steam下载游戏占用内存
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系