bsn4/grpc
Composer 安装命令:
pie install bsn4/grpc
包简介
Rust-based gRPC extension for PHP — drop-in replacement for ext-grpc
README 文档
README
A Rust-based gRPC extension for PHP — drop-in replacement for the official ext-grpc.
Why?
The official C-based grpc extension has long-standing issues:
- ZTS/TSRM crashes — segfaults under FrankenPHP, Swoole, and other threaded SAPIs
- OpenSSL/BoringSSL conflicts — the bundled BoringSSL collides with PHP's OpenSSL, breaking
ext-curland other extensions
grpc-php-rs solves both by using a pure Rust stack: tonic for gRPC, rustls for TLS (no OpenSSL), and ext-php-rs for PHP bindings.
Install
Docker (recommended)
One line in your Dockerfile — no build tools needed:
FROM php:8.5-cli COPY --from=ghcr.io/bsn4/grpc-php-rs:latest-php8.5 /usr/local/ /usr/local/
For ZTS (FrankenPHP, Swoole, etc.):
COPY --from=ghcr.io/bsn4/grpc-php-rs:latest-php8.5-zts /usr/local/ /usr/local/
For Alpine:
FROM php:8.5-alpine COPY --from=ghcr.io/bsn4/grpc-php-rs:latest-php8.5-alpine /usr/local/ /usr/local/
Available tags: latest-php{8.2,8.3,8.4,8.5} for Debian, append -alpine for Alpine, append -zts for thread-safe (e.g. latest-php8.5-alpine-zts). Version-pinned tags like v0.2.1-php8.5-alpine are also available.
Via PIE
pie install bsn4/grpc
Requires PIE 1.4.0+ for pre-packaged binary support.
Manual download
Download the appropriate .so from the latest release, then:
# Copy to your PHP extensions directory cp grpc.so $(php -r "echo ini_get('extension_dir');") # Enable it echo "extension=grpc" > $(php -r "echo PHP_CONFIG_FILE_SCAN_DIR;")/grpc.ini
Alpine note: When using the
linux-muslbinary outside of the Docker install image, you also needapk add --no-cache libgcc. The Docker install image bundles this for you.
Supported Platforms
| PHP | OS | Arch | Thread Safety |
|---|---|---|---|
| 8.2, 8.3, 8.4, 8.5 | Linux (glibc) | x86_64 | NTS, ZTS |
| 8.2, 8.3, 8.4, 8.5 | Linux (glibc) | ARM64 | NTS, ZTS |
| 8.2, 8.3, 8.4, 8.5 | Linux (musl/Alpine) | x86_64 | NTS, ZTS |
| 8.2, 8.3, 8.4, 8.5 | Linux (musl/Alpine) | ARM64 | NTS, ZTS |
| 8.2, 8.3, 8.4, 8.5 | macOS | ARM64 | NTS |
| 8.2, 8.3, 8.4, 8.5 | Windows | x86_64 | NTS |
Usage
grpc-php-rs is a drop-in replacement. Add to your php.ini:
extension=grpc
Then use the Grpc\ namespace as normal:
$channel = new \Grpc\Channel('localhost:50051', [ 'credentials' => \Grpc\ChannelCredentials::createInsecure(), ]);
All existing gRPC PHP code works unchanged — Grpc\Channel, Grpc\ChannelCredentials, Grpc\CallCredentials, Grpc\Timeval, and all call types (UnaryCall, ServerStreamingCall, ClientStreamingCall, BidiStreamingCall).
Building from Source
Requirements:
- Rust toolchain (stable; nightly required on Windows)
- PHP 8.2+ development headers (
php-dev/php-devel)
cargo build --release
# Output: target/release/libgrpc_php_rs.so (Linux) or libgrpc_php_rs.dylib (macOS) or grpc_php_rs.dll (Windows)
Running Tests
./test.sh all # Build Docker images + run smoke & compatibility tests ./test.sh zts # ZTS stress test with FrankenPHP + concurrent requests ./test.sh smoke # PHP smoke test only ./test.sh shell # Drop into PHP CLI with extension loaded
See ./test.sh --help for all options.
License
MIT
bsn4/grpc 适用场景与选型建议
bsn4/grpc 是一款 基于 Rust 开发的 Composer 扩展包,目前已累计 953 次下载、GitHub Stars 达 30, 最近一次更新时间为 2026 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bsn4/grpc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bsn4/grpc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bsn4/grpc 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This module allows drag & drop grouping of items in a GridField
Adds text size controls and text-to-speech controls to Flarum discussion content.
Native Blade date, datetime, and date range pickers.
Symfony and Flysystem integration for the maintained KCFinder continuation.
Laravel integration for the maintained KCFinder continuation.
PHPStan rules shared across KnpLabs organization projects
统计信息
- 总下载量: 953
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 30
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-04