Download the PHP package thesis/grpc-client without Composer
On this page you can find all versions of the php package thesis/grpc-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download thesis/grpc-client
More information about thesis/grpc-client
Files in thesis/grpc-client
Package grpc-client
Short Description Async gRPC client for PHP with HTTP/2 transport, streaming RPCs, interceptors, TLS/mTLS, and client-side load balancing.
License MIT
Informations about the package grpc-client
thesis/grpc-client
Read-only subtree split from
https://github.com/thesis-php/grpc.Do not open issues/PRs here. Use the monorepo:
Async gRPC client for PHP with HTTP/2 transport, streaming RPCs, interceptors, TLS/mTLS, and client-side load balancing.
Contents
- Installation
- Requirements
- Basic usage
- TLS and mTLS
- Target addressing
- Load balancing
- Endpoint resolution
- Error handling
- Compression
- Interceptors
- Client streaming
- Server streaming
- Bidirectional streaming
- Closing the client
Installation
Requirements
To generate gRPC client classes from .proto, use:
Basic usage
You can pass request metadata too:
TLS and mTLS
Target addressing
The target string passed to withHost() follows gRPC name resolution format: scheme:endpoint.
Supported schemes:
| Scheme | Format | Description |
|---|---|---|
dns |
dns:///host:port or dns://authority/host:port |
Resolves hostname via DNS. Supports periodic re-resolution based on TTL. |
ipv4 |
ipv4:addr1:port1,addr2:port2 |
Comma-separated IPv4 addresses, no DNS lookup. |
ipv6 |
ipv6:[addr1]:port1,[addr2]:port2 |
Comma-separated IPv6 addresses in bracket notation. |
unix |
unix:///path/to/socket |
Connects via Unix domain socket. |
passthrough |
passthrough:///address |
Passes address through as-is without resolution. |
If scheme is omitted, dns is assumed:
Use custom DNS server with authority:
Multi-endpoint target without DNS:
Load balancing
When resolution returns multiple addresses, the load balancer picks endpoint per RPC.
Built-in policies:
PickFirstFactory(default): shuffles endpoint list, picks one, and keeps it pinned until it disappears after refresh.RoundRobinFactory: cycles through all available endpoints.
With DNS targets, resolver can re-resolve by TTL and call balancer refresh() with updated endpoints. Re-resolution interval is clamped between minimum and maximum bounds (default 30..300 seconds).
Custom load balancer example:
Endpoint resolution
Resolver is selected by target scheme. You can override the resolver for a scheme:
Default resolvers by scheme:
dns->DnsResolveripv4,ipv6,unix->StaticResolverpassthrough->PassthroughResolver
Custom schemes (service discovery)
Register a resolver under any scheme to plug in a service registry such as etcd or
Consul. The target is then <scheme>://[authority]/<endpoint>, and the endpoint is
handed to the resolver as $target->opaque:
An EndpointResolver returns the current Resolution and may push updates over time
through EndpointResolverListener::onResolve(), which the balancer picks up live.
Error handling
Compression
Compression reduces payload size and is useful for large protobuf messages or bandwidth-constrained links.
Interceptors
Interceptors let you add cross-cutting logic (auth, logging, tracing, metadata enrichment) without changing service stubs. Mirroring gRPC, they come in two flavours, registered on separate chains:
UnaryInterceptorwraps a whole unaryrequest → responsecall (viawithUnaryInterceptors()). A retry policy, for instance, is naturally a unary interceptor — re-invoking$invokerreuses the call's pick context, so the transport fails over to another endpoint automatically.StreamInterceptorwraps the creation of a stream (viawithStreamInterceptors()), and so also covers the underlying stream of every streaming RPC.
A unary call does not run the stream chain and vice versa. An interceptor that must apply to both (e.g. auth) implements both interfaces and is registered on both chains.
Client streaming
Use client streaming when you need to send many messages and receive one final aggregated response.
Server streaming
Use server streaming when a single request should return a sequence of server messages.
Bidirectional streaming
Use bidirectional streaming for conversational protocols where both sides can send messages independently.
Closing the client
Call Client::close() to stop background resolver activity and release resources, especially when DNS re-resolution is enabled.
All versions of grpc-client with dependencies
amphp/cache Version ^2.0
amphp/dns Version ^2.4
amphp/http Version ^2.1
amphp/http-client Version ^5.3
amphp/socket Version ^2.3
league/uri Version ^7.8
thesis/grpc-protocol Version ^0.4