我已经设置了geth Ether测试网络。我想通过IPC PHP与客户端进行通信。我在Ubuntu上。这是我当前的代码:
$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)这是IPC文件(FIFO?):
srwxrwxrwx 1 john john 0 Jun 17 01:30 geth.ipc=这个运行得很好。
echo '{"jsonrpc":"2.0","method":"rpc_modules","params":[],"id":1}' | nc -U geth.ipc我不确定如何真正与客户沟通。发送时没有响应。在msg_receive上,它只返回最初发送的消息。
有人经验丰富,好心给我一个合适的解决方案吗?
发布于 2017-06-17 21:59:57
更新:我发现了它是如何工作的。我使用了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 );而不是使用消息队列,我可以让它工作与简单的PHP套接字到IPC文件!
发布于 2019-12-25 17:48:54
如果ipc的结果是动态的,最好使用socket_read,直到最后一个字符是"\n“。然后像这样处理结果
public function ipcCall($data){
$sock = socket_create(AF_UNIX, SOCK_STREAM, 0);
socket_connect($sock, "/home/someuser/.ethereum/testnet/geth.ipc", 1);
$msg = json_encode($data);
socket_send($sock, $msg, strlen($msg), MSG_EOF);
$result = '';
while (($currentByte = socket_read($sock, 1)) != "\n") {
$result .= $currentByte;
}
var_dump($result);
}https://stackoverflow.com/questions/44603733
复制相似问题