189 8069 5689

GO为server,PHP为client的实践-创新互联

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:

创新互联长期为近1000家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为阜平企业提供专业的成都网站设计、网站建设,阜平网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。

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--.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

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站栏目:GO为server,PHP为client的实践-创新互联
本文路径:http://cdxtjz.cn/article/cecegd.html

其他资讯