Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
laravel怎么通过rpc调用golang程序_创想鸟

laravel怎么通过rpc调用golang程序

                                                       

下面由laravel教程栏目给大家介绍laravel怎么通过rpc调用golang程序 ,希望对需要的朋友有所帮助!

Golang 服务端

package mainimport (    "fmt"    "net"    "net/rpc"    "net/rpc/jsonrpc")type Goods struct{}//方法(必须是公有方法,且必须是两个参数)func (g *Goods) GetName(args string , res *string) error {    *res = "args=" + args    return nil}func main() {    //注册rpc服务,并自定义服务名    err := rpc.RegisterName("Goods",new(Goods))    if err != nil {        panic(err.Error())    }    //监听端口,如果监听所有客户端则去掉ip    listen, err := net.Listen("tcp", "127.0.0.1:7081")    if err != nil {        panic(err.Error())    }    fmt.Println("启动服务...")    for {        conn, err := listen.Accept() // 接收客户端连接请求        if err != nil {            continue        }        go jsonrpc.ServeConn(conn)    }}

PHP 客户端

public function test(){      $host = '127.0.0.1';      $port = '7081';      $conn = fsockopen($host, $port, $errno, $errstr, 3);      if (!$conn) {          dd('链接失败');      }      $method = 'Goods.GetName';      $params = "我是字符串参数";      $err = fwrite($conn, json_encode(array(              'method' => $method,              'params' => [$params],              'id' => 0,          ))."\n");     if ($err === false){         dd('写入数据失败');      }     stream_set_timeout($conn, 0, 30000);//超时配置     $line = fgets($conn);     if ($line === false) {         dd('获取响应数据失败');      }     dd(json_decode($line,true));}

返回结果

array:3 [  "id" => 0  "result" => "args=我是字符串参数"  "error" => null]

推荐:最新的五个Laravel视频教程

以上就是laravel怎么通过rpc调用golang程序的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/348252.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
Moonlight-16B-A3B— 月之暗面开源的 MoE 模型
上一篇 2025年11月5日 21:15:28
Win7系统怎么看电脑内存大小?.
下一篇 2025年11月5日 21:15:31

相关推荐

发表回复

登录后才能评论
关注微信