Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Consul Php Sdk Laravel Package

friendsofphp/consul-php-sdk

A thin PHP wrapper around the Consul HTTP API, covering agent, catalog, health, kv, session, and txn services. It returns ConsulResponse objects, throws typed exceptions, and includes helpers for locks and semaphores.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit

  • This is a framework-agnostic HTTP SDK, not a Laravel package. No service provider, no facade, no publishable config, no package discovery. It is a thin, consistent wrapper over the Consul CE HTTP API (agent, catalog, health, kv, session, txn, plus the full surface added in 5.4: ACL, Config, Connect, Coordinate, DiscoveryChain, Event, Operator, Peering, PreparedQuery, Snapshot, Status).
  • Consul is infrastructure, and this is the only credible PHP-native path to it. Fit at the HTTP layer is good; fit at the framework layer is zero by design. Treat "install the SDK" and "integrate Consul into the app" as two distinct work items.
  • Where it genuinely earns its place in a Laravel estate: service registration/health for a multi-service deployment; distributed locking and leader election for scheduled jobs (a real gap — Laravel's onOneServer depends on a shared cache, and Consul sessions are a legitimate alternative if Consul is already the platform bet); KV for runtime config/feature flags; Snapshot + Operator for DR and cluster-health tooling that previously lived only in Go/Terraform workflows.
  • Where it does not fit: single-app or monolith deployments; teams that only need KV (Redis/etcd is simpler); teams expecting Laravel-native cache/queue/session drivers — no such drivers exist and you would be writing them.

Integration feasibility

  • Clean Composer install if PHP ≥ 8.2 and symfony/http-client ≥ 6.4. Laravel 11/12 already require PHP 8.2, so the floor is normally satisfied incidentally. The real gate is the symfony/http-client pin if that component is already a direct or transitive dependency.
  • Usable on day one with zero ceremony (new Consul\Services\KV()), but that is also the trap: without a binding, you get new KV() scattered across the codebase with hardcoded addresses and no token handling. The binding is the actual scoping item, and it is small but mandatory (~3–5 engineering days including tests).
  • Testing requires a live Consul agent; the package ships no mock transport. symfony/http-client's MockHttpClient makes unit-level stubbing viable, and a Consul container in CI covers contract behavior. Budget for it — there is no hosted sandbox.

Technical risk

  • Ecosystem/adoption risk, not code risk. The metadata shows 0 dependents against ~317 stars, which is why the composite score sits at 23 despite an active, reputable maintainer (FriendsOfPHP) and clean changelog discipline. Low downstream validation means you are the canary: write your own endpoint-level contract tests for the endpoints you actually call. The blast radius per endpoint is small (thin mapping), so this is manageable, not disqualifying.
  • Distributed-correctness risk is the real exposure, and it sits above the SDK. Locks and semaphores are advisory, session-TTL-bound, and do not auto-renew. A lost session silently releases the lock while work continues. Fencing tokens and idempotency are your design decisions.
  • Dependency-floor churn: 5.4 is a minor version with breaking floors (PHP 8.1→8.2, http-client 5.4→6.4, psr/log 1→2). Evidence that "minor" here is not SemVer-safe in the dependency graph. Pin deliberately; do not allow unattended composer update.
  • Error-handling surface is two hierarchies, not one. 4xx → ClientException, 5xx → ServerException, but transport/TLS/DNS failures surface as Symfony TransportExceptionInterface. Code that only catches the SDK's exceptions will 500 on an agent outage.
  • Blocking queries are now first-class options, which is a feature and a footgun in PHP-FPM (see Operational Impact).

Key questions

  • Do we actually need Consul, or is Redis/DB plus onOneServer sufficient for locking and config? Decide the platform bet before the SDK bet — this package is downstream of that decision.
  • Who owns the Laravel binding — platform team as a reusable internal package, or app team as a one-off?
  • What is the topology: local agent per host/container (recommended; matches the SDK's localhost:8500 default) or remote server addressing from every app node?
  • ACL token delivery: CONSUL_HTTP_TOKEN env (SDK-native, aligns with container/CI conventions) or a secrets manager? If env, does that meet our secret-handling standard, and what is the rotation runbook? A rotated token that misses one service produces a ClientException that looks like an outage.
  • Do we need any Consul Enterprise capability (namespaces, admin partitions, SSO, Sentinel)? If yes, this package stops at CE and the whole evaluation changes.
  • What is the acceptable degradation when Consul is unreachable: fail-closed (app won't boot) or fail-open (serve cached config)? This determines whether Consul can ever sit on a web request path.
  • Is the PHP 8.2 upgrade already complete, or does it gate the timeline? On 8.1 you are capped at 5.3 and lose the full API surface.

Integration Approach

Stack fit

  • Target is Laravel 11/12 on PHP 8.2+. Laravel 10 on PHP 8.1 is excluded by the 5.4 floor; 5.3 is the fallback but forfeits the complete API coverage that motivated the upgrade.
  • Accept two HTTP stacks: symfony/http-client (SDK) alongside Laravel's Guzzle-based Http facade. Frame it as isolation, not duplication — Consul timeouts, pooling, and circuit breaking stay independent of application HTTP traffic. Flag it in the dependency footprint review so nobody "consolidates" it later.
  • psr/log 2/3 aligns with Monolog 3 in Laravel 10+. Bridge the existing PSR logger so SDK logs land in the app's normal channels.

Migration path

  • Nothing to migrate unless you carry hand-rolled curl/Guzzle calls to Consul, or a fork of the pre-5.0 package. A fork is a genuine migration: namespace change (SensioLabs\Consul → Consul), typed request bodies (arrays now, not strings), removed factory and most interfaces. Scope it explicitly; it is not a composer require.
  • If this replaces Eureka/Nacos, run both registries in parallel behind a config flag until every discovery consumer is cut over. Do not dual-write lock/session state — pick one authority per concern.

Compatibility

  • Run composer why-not friendsofphp/consul-php-sdk 5.4 against the real lockfile before committing. Highest-probability conflicts: a pinned symfony/http-client, psr/log 1.x transitives, and PHP 8.1 CI runners.
  • Pin ^5.4 with an explicit upgrade policy and a CI gate on the lockfile diff.
  • Symfony 6.4 LTS and 7.x are both in range and are the realistic PHP 8.2 path; Symfony 8.1+ is permitted but implies a newer PHP baseline, so treat it as a future state, not today's.

Sequencing

  1. Decision spike (1 week): confirm Consul as the platform bet, verify lockfile resolution, choose token delivery, agree the fail-open/fail-closed posture.
  2. Binding build (3–5 days): ConsulServiceProvider, config/consul.php (scheme, host, port, token, timeouts, DC), singleton ClientInterface + per-service bindings, facade, a Consul health check surfaced to ops, PSR logger bridge, and a retry/circuit-breaker wrapper — the SDK has none.
  3. Pilot (one sprint, read-mostly): service registration, health, KV reads with blocking queries executed only from queued workers, never from web requests. Instrument latency and failure rates.
  4. Locks and leader election (separate release): ship behind a flag with a kill switch, with fencing tokens and idempotent job bodies designed up front.
  5. Platform-tier capabilities (platform team, not app teams): Connect intentions, Peering, Snapshot + Operator for DR and cluster reporting.
  6. Retire legacy discovery/config mechanisms.

Sequencing rule: phases 3 and 4 must not share a release. Locking changes correctness semantics; it needs its own rollback story.

Operational Impact

Maintenance

  • Low ongoing code maintenance — thin wrapper, active maintainer, disciplined changelog, and Consul's own API is stable. Non-zero binding maintenance: the provider, config schema, retry wrapper, and contract tests are yours permanently.
  • Track releases for another minor-with-breaking-floors. One dependency-hygiene review per quarter is the right cadence.
  • With 0 dependents there is no crowd-sourced bug discovery. Own endpoint-level contract tests against a pinned Consul version in CI; that is the mitigation, not a nice-to-have.

Support

  • MIT, GitHub issues, no SLA, no commercial backing. Maintainer responsiveness has historically been good, so the realistic risk is a blocked upgrade, not a blocked incident.
  • Mitigation is cheap and specific: because the SDK is a thin HTTP wrapper, any single problematic endpoint can be bypassed with Http::withToken()->put(...) while you wait. That keeps worst-case severity low. Document that escape hatch.
  • Name an internal owner for the binding before phase 2. Unowned integration code decays fastest.

Scaling

  • The SDK is stateless; all scaling questions are Consul topology questions. Run a local agent per host/container and let the SDK hit its localhost:8500 default. This is the design the SDK assumes and it prevents every app node from hammering the server cluster directly.
  • Blocking queries hold a PHP-FPM worker for the wait window. M concurrent watchers = M workers permanently occupied. Cap concurrency, run watchers as long-lived Horizon/queue workers, or prime a cache in the background and read the cache in the request path.
  • Sessions have a TTL floor and lock acquisition is a KV write on every attempt. A single hot lock key at high schedule frequency is a real contention point — stagger job starts or shard lock keys.
  • The SDK does no batching: request volume is linear in (services × instances), plus health intervals. Size the Consul server cluster for that shape before onboarding many services.

Failure modes

  • Agent unreachable / DNS / TLS: surfaces as TransportExceptionInterface, not an SDK exception. Unhandled, it is a hard 500 on every request path that touches Consul. Never call Consul synchronously in a hot path without a timeout and a cached fallback.
  • 4xx (ClientException): most often ACL token misconfiguration or a missed rotation. Alert on it distinctly from generic errors — it is a config bug, not an outage, and the remediation is different.
  • 5xx (ServerException): typically leader election. Transient; retry-with-backoff is your code.
  • Silent lock loss on session TTL expiry: the most damaging failure here. One node's session expires, another acquires the lock, the first keeps working. Mitigate with fencing tokens, idempotent operations, and session renewal (which you must build).
  • Stale reads: a KV read after a write can return old config depending on consistency mode. Now that stale/consistent are first-class options, choose per call site deliberately rather than accepting the default.
  • Unverified snapshot jobs: a "successful" backup to a broken target is worse than a visible failure. Add checksum validation and run a restore drill.
  • Ownership drift: KV values consumed by applications but owned by no team. Assign ownership or expect silent breakage.

Ramp-up

  • The SDK is a half-day to learn — four conventions (mandatory args first, options array, ConsulResponse return, typed exceptions). The real learning curve is Consul itself: ACLs, sessions, blocking queries, consistency modes, agent-vs-server topology. Budget 2–3 engineers for Consul literacy, not SDK training.
  • Laravel developers will expect a facade and a config file. Shipping the binding is what converts a dependency into an adopted capability. Ship it with a README and two worked examples — a KV read with a fallback, and a lock wrapped around a scheduled job — or expect copy-pasted service instantiation to spread.
  • Make the runbook part of the pilot exit criteria: what to do when Consul is down, how to rotate the ACL token, how to verify a held lock. Without it, every Consul blip becomes a platform-team page, and the operational cost story collapses.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator