跳至正文
Wener Notes

gRPC PHP

约 1 分钟阅读
标签:PHP
bash
composer require grpc/grpc
composer require google/protobuf

# /opt/homebrew/lib/php/pecl/<ABI_VERSION>/grpc.so
pecl install grpc       # by pecl - e.g. macOS
apk add php82-pecl-grpc # AlpineLinux

php -i | grep "PHP Extension Build" # ABI 版本
json
{
  "autoload": {
    "psr-4": {
      "App\\": "app/",
      "": "gen/"
    }
  },
  "require": {
    "grpc/grpc": "^1.41",
    "google/protobuf": "^3.19",
    "ext-grpc": "*"
  }
}
php.ini
extension=grpc.so
php
<?php
$client = new Helloworld\GreeterClient('localhost:50051', [
  // 'credentials' => Grpc\ChannelCredentials::createSsl(file_get_contents('<path to certificate>')),
  'credentials' => Grpc\ChannelCredentials::createInsecure(),
  'grpc.primary_user_agent' => 'my-user-agent-identifier',
  'grpc.max_receive_message_length' => 8*1024*1024,
  'grpc.default_compression_algorithm' => 2,
  'grpc.default_compression_level' => 2,
]);
ini
# pcntl_fork
grpc.enable_fork_support = 1
grpc.poll_strategy = epoll1

# Tracing and Logging
# /var/log/grpc.log
grpc.grpc_verbosity=debug
grpc.grpc_trace=all,-polling,-polling_api,-pollable_refcount,-timer,-timer_check

grpc.default_compression_algorithm

text
0: No compression
1: Compress with DEFLATE algorithm
2: Compress with GZIP algorithm
3: Stream compression with GZIP algorithm

grpc.default_compression_level

text
0: None
1: Low level
2: Medium level
3: High level

关联信息

反向链接、本文链接的其他页面和外部资料。

参考资料

GitHub1 条
最近更新commit 180567c编辑