• mac环境下安装grpc的PHP客户端


    前言

    自己本地环境原本有个PHP7.1的版本,结果在装grpc时一直提示没有权限把grpc.so拷贝到PHP扩展目录下,就重新装了一次php

    此次安装涉及的有:

    • PHP
    • composer
    • pecl
    • grpc
    • php的grpc扩展
    • protobuf
    • php的protoc插件

    安装

    1.覆盖原来的php

    # 安装PHP
    brew intall php
    
    # 优先使用新安装的PHP7.2,即配置环境变量,这一步要注意自己的PHP目录,以下是我的目录
    # 我的shell使用的是zsh,所以导入到~/.zshrc下,要注意自己的shell是什么,导入到自己使用的shell配置文件里
    echo 'export PATH="/usr/local/opt/php@7.2/bin:$PATH"' >> ~/.zshrc
    echo 'export PATH="/usr/local/opt/php@7.2/sbin:$PATH"' >> ~/.zshrc
    
    # 使用配置文件,使其生效
    source ~/.zshrc
    # 查看PHP的版本是否是自己安装的
    php -v 
    php-fpm -v 
    
    

    2.安装grpc及其扩展

    安装grpc

    brew install grpc 
    

    安装PHP的grpc扩展

    git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc
    
    cd grpc
    git submodule update --init
    make
    sudo make install
    #这一步我本地报错找不到autolocal,查后需要安装automake,用brew install automake即可
    
    cd grpc/src/php/ext/grpc
    phpize
    ./configure
    make
    sudo make install
    

    以上都OK的话,在phpinfo里应该可以看到grpc的信息了

    3.安装protobuf

    pecl install protobuf
    

    安装成功后,phpinfo里会有protobuf的信息.

    4.demo

    下载example

    $ # Clone the repository to get the example code:
    $ git clone -b v1.24.0 https://github.com/grpc/grpc
    $ # Build grpc_php_plugin to generate proto files if not build before
    $ cd grpc && git submodule update --init && make grpc_php_plugin
    $ # Navigate to the "hello, world" PHP example:
    $ cd examples/php
    $ ./greeter_proto_gen.sh
    $ composer install
    

    我本地跑的是go的grpc服务端,所以不安装服务端了。demo里是用node做服务端。如下:

    $ npm install
    $ cd dynamic_codegen
    $ node greeter_server.js	
    

    运行PHP的客户端:

    $ ./run_greeter_client.sh	
    
    没问题的话,在服务端会显示:
    $ 2019/10/18 16:03:50 Received: world
    

    参考链接:
    https://grpc.io/docs/quickstart/php/
    go安装grpc链接

  • 相关阅读:
    Grid++Report 报表开发工具
    docker(1):virtualbox 安装CoreOS系统,配置registry-mirror
    [Network]Introduction and Basic concepts
    Java进程堆外内存(off heap)大小
    可设置指定时间自己主动消失的 MessageBox实现
    《iOS Human Interface Guidelines》——Wallet
    什么是OpenStack
    Filters.h各种信号恢复滤波器头文件
    Android时间轴效果,直接使用在你的项目中
    浅析C++多重继承
  • 原文地址:https://www.cnblogs.com/efan/p/11699117.html
Copyright © 2020-2023  润新知