温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

GO为server,PHP为client的实践

发布时间:2020-07-06 11:08:10 来源:网络 阅读:231 作者:dfwasds 栏目:web开发

1> Ubuntu16.04 集成的go包是1.6,后期有坑,直接安装1.9.
To install Go 1.9 on Ubuntu 16.04, first add the PPA and install the golang-1.9-go package:

sudo add-apt-repository ppa:gophers/archive
sudo apt update
sudo apt-get install golang-1.9-go
The add go the go path to the your PATH:

echo "export PATH=$PATH:/usr/lib/go-1.9/bin" >> ~/.profile
Then finally load the new path:

source ~/.profile
Although everything should now work, it might be wise to just log out and back in to make sure other programs also get the updated path.

2>配置好GOPATH;
export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOPATH/bin

之后protoc-gen-go会放到 $GOBIN 下

3>安装protoc 3.6.1
直接复制模式
Install Protocol Buffers v3
Install the protoc compiler that is used to generate gRPC service code. The simplest way to do this is to download pre-compiled binaries for your platform(protoc-<version>-<platform>.zip) from here: https://github.com/google/protobuf/releases

Unzip this file.
Update the environment variable PATH to include the path to the protoc binary file.

4> Install gRPC
go get -u google.golang.org/grpc

5> Install the protoc plugin for Go
go get -u github.com/golang/protobuf/protoc-gen-go

6>Download the example
You can found under the examples dir: $GOPATH/src/google.golang.org/grpc/examples

7>Build the example
helloworld.proto => helloworld.pb.go

    protoc -I helloworld/ helloworld/helloworld.proto --go_out=plugins=grpc:helloworld

8>在俩个窗口执行
go run greeter_server/main.go
go run greeter_client/main.go
以上就是go服务端/ go客户端

=========================================================

1>安装grpc_php_plugin等插件
1》sudo apt-get install php7.0 php7.0-dev php-pear phpunit
2》Install Composer (Linux or Mac):
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
3安装扩展
sudo pecl install grpc
sudo pecl install grpc-1.7.0
sudo pecl install protobuf
sudo pecl install protobuf-3.4.0
update php.ini
4》安装插件
$ git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc
$ cd grpc
$ git submodule update --init
$ make //编译全部插件
$ make grpc_php_plugin //只编译php插件

如果有这个报错 defined but not used [-Werror=unused-variable]
找到Makefile,去掉其中-Werror ,重新编译。

5》 find php example
cd examples/php (grpc/examples/php)

6》helloworld.proto => hello.world.pb.go
./greeter_proto_gen.sh

7》执行client之前,需要引包
composer install

8》服务端是go,现在客户端在php
./run_greeter_client.sh

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI