Skip to content

Instantly share code, notes, and snippets.

@copuzzle
Last active April 12, 2018 10:46
Show Gist options
  • Save copuzzle/286ae2d7e5ab3e8d88a6755107ba83c8 to your computer and use it in GitHub Desktop.
Save copuzzle/286ae2d7e5ab3e8d88a6755107ba83c8 to your computer and use it in GitHub Desktop.

php的grpc扩展 下载地址: http://pecl.php.net/package/gRPC 安装过程:

phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
# 添加grpc.so到php.ini配置
vim /usr/local/php/etc/php.ini
extension = "grpc.so"
php -m | grep "grpc"
grpc

但是如果 gcc 小于 4.8 版本可能会:

mkdir src/php/ext/grpc/.libs
 cc -fvisibility=hidden -DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN -D_HAS_EXCEPTIONS=0 -DNOMINMAX -DGRPC_ARES=0 -I. -I/data/grpc-1.10.1 -DPHP_ATOM_INC -I/data/grpc-1.10.1/include -I/data/grpc-1.10.1/main -I/data/grpc-1.10.1 -I/usr/local/php-5.5.9/include/php -I/usr/local/php-5.5.9/include/php/main -I/usr/local/php-5.5.9/include/php/TSRM -I/usr/local/php-5.5.9/include/php/Zend -I/usr/local/php-5.5.9/include/php/ext -I/usr/local/php-5.5.9/include/php/ext/date/lib -I/data/grpc-1.10.1/include -I/data/grpc-1.10.1/src/php/ext/grpc -I/data/grpc-1.10.1/third_party/boringssl/include -DHAVE_CONFIG_H -Wall -Werror -Wno-parentheses-equality -Wno-unused-value -std=c11 -g -O2 -c /data/grpc-1.10.1/src/php/ext/grpc/byte_buffer.c  -DPIC
cc1: 错误:无法识别的命令行选项“-std=c11”
cc1: warnings being treated as errors
cc1: 错误:无法识别的命令行选项“-Wno-parentheses-equality”
make: *** [src/php/ext/grpc/byte_buffer.lo] 错误 1

需要安装 gcc 4.8 , 可能通过:

wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo
yum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++

安装新版本的 gcc, 但不覆盖系统的 gcc ,使用的时候通过 scl 启用,相当于python多版本的虚拟机一样:

scl enable devtoolset-2 bash
//然后再执行
make 

不过中间又有一个小插曲, 使用 grpc-1.10.1 编译的时候出现了

ird_party/boringssl/third_party/fiat/.libs/curve25519.o   -Wl,-soname -Wl,grpc.so -o .libs/grpc.so
/opt/rh/devtoolset-2/root/usr/libexec/gcc/x86_64-redhat-linux/4.8.2/ld: src/php/ext/grpc/.libs/call.o: relocation R_X86_64_32 against `free_wrapped_grpc_call' can not be used when making a shared object; recompile with -fPIC
src/php/ext/grpc/.libs/call.o: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [grpc.la] 错误 1

这样的错误,最后通过使用 grpc-1.11.0RC2 版本解决问题.

参考: php-grpc-client https://blog.csdn.net/xuduorui/article/details/77726393
pecl:
https://blog.csdn.net/xuduorui/article/details/77726393
gcc version:
grpc/grpc#8032
scl gcc 4.8:
https://superuser.com/questions/381160/how-to-install-gcc-4-7-x-4-8-x-on-centos
scl :
https://linux.cn/article-6776-1.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment