highperapp / grpc
High-Performance gRPC Server with Rust FFI acceleration and pure PHP fallback
dev-main
2025-07-16 16:17 UTC
Requires
- php: ^8.3|^8.4
- ext-ffi: *
- amphp/http-server: ^3.0
- amphp/parallel: ^2.0
- amphp/socket: ^2.0
- google/protobuf: ^3.21
- psr/log: ^3.0
Requires (Dev)
- phpunit/phpunit: ^10.0|^11.0
- squizlabs/php_codesniffer: ^3.7
This package is auto-updated.
Last update: 2025-07-16 16:19:46 UTC
README
High-Performance gRPC Server with Rust FFI acceleration and pure PHP fallback for ultra-fast RPC communication. Built with Hybrid Multi-Process + Async architecture using AMPHP v3.
Features
- ๐ Rust FFI Acceleration with pure PHP fallback
- ๐ Hybrid Multi-Process + Async Architecture using AMPHP v3
- ๐ก๏ธ Circuit Breaker & Retry Patterns for fault tolerance
- ๐ฆ Framework Integration via PSR-11 service provider
- ๐งช Comprehensive Testing (Unit, Integration, Performance, Concurrency, Reliability)
- ๐ง Standalone & Framework Usage supported
- ๐ High Performance with parallel processing support
Requirements
- PHP 8.3+ or PHP 8.4+
- ext-ffi (for Rust acceleration)
- AMPHP v3+
- google/protobuf
Installation
composer require highperapp/grpc
Quick Start
Standalone Usage
<?php use HighPerApp\HighPer\GRPC\GrpcServerFactory; use HighPerApp\HighPer\GRPC\Examples\GreeterService; // Configuration $config = [ 'host' => '0.0.0.0', 'port' => 9090, 'worker_processes' => 4, 'parallel_workers' => 2, 'circuit_breaker' => ['enabled' => true], 'retry' => ['enabled' => true], 'engine' => ['rust_acceleration' => true] ]; // Create server $factory = new GrpcServerFactory($config); $server = $factory->createHighPerformanceServer(); // Register service $server->registerService(new GreeterService()); // Start server $server->start();
Framework Integration
<?php use HighPerApp\HighPer\GRPC\ServiceProvider\GrpcServiceProvider; // In your framework's service container $grpcProvider = new GrpcServiceProvider($container, $config); $grpcProvider->register(); $grpcProvider->boot(); // Register services $grpcProvider->registerService(YourService::class); // Get server $server = $grpcProvider->getServer();
Architecture
- Hybrid Multi-Process + Async: Combines process isolation with async I/O
- AMPHP v3 Integration: Uses amphp/parallel for CPU-intensive tasks
- Circuit Breaker Pattern: Prevents cascade failures
- Retry Mechanism: Automatic retry with exponential backoff
- Dual Engine: Rust FFI for performance + PHP fallback for compatibility
Configuration
$config = [ 'host' => '0.0.0.0', 'port' => 9090, 'worker_processes' => 4, 'parallel_workers' => 2, 'circuit_breaker' => [ 'enabled' => true, 'failure_threshold' => 5, 'timeout_seconds' => 60 ], 'retry' => [ 'enabled' => true, 'max_attempts' => 3, 'base_delay_ms' => 100 ], 'engine' => [ 'rust_acceleration' => true, 'fallback_to_php' => true ] ];
Testing
# Run all tests composer test # Run specific test suites composer test:unit composer test:integration composer test:performance composer test:concurrency composer test:reliability # Code coverage composer test:coverage # Code style composer cs-check composer cs-fix
Examples
See the examples/
directory for:
server.php
- Standalone server setupclient.php
- Client usageframework-integration.php
- Framework integration exampleGreeterService.php
- Example service implementation
Performance
- High Throughput: Designed for high-concurrency scenarios
- Low Latency: Rust FFI acceleration for critical paths
- Resource Efficient: Process isolation with shared worker pools
- Fault Tolerant: Circuit breaker and retry patterns
Security
- TLS/HTTPS support (configurable)
- Input validation and sanitization
- Rate limiting capabilities
- Secure by default configuration
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License
MIT License - see LICENSE file for details.