- Can I use spiral/grpc-client in Laravel without Spiral Framework?
- Yes, the package supports standalone usage. Register the `GrpcClient` via Laravel’s service provider or manually instantiate it. Interceptors and DTO-based config work identically in both Spiral and Laravel. Just ensure the PECL gRPC extension is installed.
- How do I install and configure spiral/grpc-client in Laravel?
- Run `composer require spiral/grpc-client`, then register the client in a service provider using `app->singleton(GrpcClient::class, fn() => GrpcClient::create(config('grpc.connections')))`. Configure endpoints, interceptors, and timeouts in `config/grpc.php`.
- What Laravel versions does spiral/grpc-client support?
- The package is framework-agnostic but works with Laravel 8.x–10.x. Ensure your PHP version (8.1+) matches Laravel’s requirements. Spiral’s core dependencies (like gRPC) are version-agnostic for Laravel.
- How do I handle gRPC errors in Laravel exceptions?
- Use the package’s dedicated exceptions (e.g., `GrpcException`, `StatusException`) and catch them in Laravel’s exception handler. Map gRPC status codes (e.g., `UNAVAILABLE`) to Laravel’s `HttpException` or custom exceptions for consistency.
- Does spiral/grpc-client support retries and timeouts?
- Yes, use built-in interceptors like `RetryInterceptor` and `SetTimeoutInterceptor`. Configure them via `withInterceptors()` or DTO factories. For example, `RetryInterceptor::createConfig(maximumAttempts: 3)` retries failed calls up to 3 times.
- How do I generate gRPC service interfaces for PHP?
- Use `protoc` with the PHP gRPC plugin: `protoc --php_out=. --grpc_out=. --plugin=protoc-gen-grpc=$(which grpc_php_plugin) api.proto`. Store generated `.php` files in your project and version-control them or auto-generate them in CI.
- What’s the best way to log gRPC calls in Laravel?
- Create a custom interceptor (e.g., `LogInterceptor`) that injects Laravel’s `Log` facade. Log requests/responses in the interceptor’s `handle()` method. Example: `Log::info('gRPC call', ['method' => $method, 'response' => $response])`.
- Can I use spiral/grpc-client with Laravel queues or Horizon?
- No, the package doesn’t natively integrate with Laravel queues. gRPC calls are synchronous by design. For async workflows, dispatch a job that calls the gRPC client, then return a queueable response.
- What are the deployment challenges with the PECL gRPC extension?
- The extension requires PECL installation (e.g., `pecl install grpc`). For Docker, use a base image with PHP + gRPC pre-installed (e.g., `php:8.2-cli` with `RUN pecl install grpc`). Test locally with `php -m | grep grpc` to verify.
- Are there alternatives to spiral/grpc-client for Laravel?
- For Laravel, consider `grpc/grpc` (low-level) or `reactphp/grpc` (async). For Spiral, `spiral/grpc-client` is optimized. If you need Guzzle-like simplicity, this package bridges that gap for gRPC. Alternatives lack Laravel integration or interceptor flexibility.