带geth Ethereum的PHP IPC

带geth Ethereum的PHP IPC,php,laravel,ipc,ethereum,Php,Laravel,Ipc,Ethereum,我已经设置了以太测试网。我想通过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"

我已经设置了以太测试网。我想通过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?):

这很好用

echo '{"jsonrpc":"2.0","method":"rpc_modules","params":[],"id":1}' | nc -U geth.ipc
我不知道如何与客户真正沟通。发送时它没有响应。在
msg_receive
上,它只返回最初发送的消息

有人能给我一个合适的解决方案吗?

更新: 我发现了它的工作原理。我曾经


不用使用MSG队列,我可以让它与IPC文件的简单PHP套接字一起工作

如果ipc的结果具有动态大小,最好使用套接字读取,直到最后一个字符为“\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);
}
$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     );
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);
}