centrifugal/phpcent
PHP client library for Centrifugo v5 HTTP API. Publish, broadcast, subscribe, manage presence and history, plus generate JWT connection and subscription tokens. Install via Composer with composer require centrifugal/phpcent:~6.0.
Architecture fit. phpcent is a thin, single-responsibility HTTP client: it wraps Centrifugo v5's server HTTP API over cURL and mints JWTs (connection and subscription tokens). It ships no Laravel service provider, facade, config file, or contracts — that is a feature, not a gap. It slots in as an outbound adapter in the service layer, callable from controllers, queued jobs, event listeners, and Artisan commands. The critical architectural boundary to state explicitly in any plan: phpcent is server-to-server only. It does not open WebSockets, manage reconnects, or touch the browser. A complete real-time feature is phpcent + a token endpoint + Centrifugo + centrifuge-js on the frontend. Estimates that treat this package as "the real-time layer" are short by an entire frontend workstream.
Integration feasibility. Low-friction. composer require centrifugal/phpcent:~6.0, instantiate new \phpcent\Client($endpoint, $apiKey, $secret), and the full surface is available: publish, broadcast, subscribe/unsubscribe, disconnect, presence, presenceStats, history, historyRemove, channels, info, batch, plus generateConnectionToken/generateSubscriptionToken with optional TTLs and metadata. Configuration knobs are sensible: connect/request timeouts, setUseAssoc(true) for array responses, custom cert/CA path, forceIpResolveV4() for broken IPv6 resolution. The one hard prerequisite is a running Centrifugo v5 instance — the package is useless without it, and that server is the real integration.
Technical risk.
config/*.php or the repository. Token forgery is the blast radius of a leaked secret.setSafety(false) disables TLS verification — acceptable only on a throwaway local box, dangerous if it reaches production. setConnectTimeoutOption(0) means "never time out," which can hang a PHP-FPM worker under network partition.Key questions.
presence, history, and channels, or only publish? Presence and history carry memory and storage costs on the server and materially change capacity planning.centrifuge-js, the token endpoint contract, reconnect/backoff behavior, and the handshake test?Stack fit. Treat phpcent as a swappable transport, not a framework citizen. Define a narrow internal contract — e.g. RealtimePublisher with publish(string $channel, array $payload), broadcast(array $channels, array $payload), and token-minting methods — and implement it with phpcent. Bind it as a singleton in a service provider, inject it, and never let \phpcent\Client leak into controllers or domain code. That single wrapper buys you: centralized error inspection, retry and logging policy, a fake for tests, and a credible path to Pusher/Ably if the self-hosted decision reverses. Keep the token endpoint as its own small controller (/api/realtime/token) that authenticates the Laravel user and returns a short-TTL connection token plus per-channel subscription tokens — short TTLs (minutes, as the README demonstrates) are the cheapest security win available.
Migration path. If replacing polling or another provider, use an adapter plus a feature flag. Sequence: (1) introduce the interface and a no-op/polling implementation so call sites are transport-agnostic; (2) add the phpcent implementation behind a config flag; (3) shadow-publish from one low-risk job while polling still drives the UI; (4) verify end-to-end delivery in staging with real Centrifugo; (5) flip the frontend to subscribe; (6) remove the polling path only after a full release cycle of clean metrics; (7) retire the old provider credentials.
Compatibility. Verify PHP version support against your Laravel runtime — the library dropped PHP <7.0 at v4 and has recent fixes for PHP 8.5 curl_close() deprecation, so it is actively tracking modern PHP. Confirm the ext-curl extension is present in all container images (it usually is, but slim base images omit it). Use setUseAssoc(true) consistently and type against arrays rather than stdClass to avoid brittle response handling. Standardize on a pinned Composer constraint (~6.0) and commit composer.lock; do not float.
Sequencing.
RealtimePublisher wrapper with response inspection, structured logging, and metrics.Maintenance. The PHP side is near-zero: small surface, infrequent releases, MIT, no transitive dependency sprawl. The real maintenance load is the Centrifugo server — upgrades, config drift, namespace changes, and engine choice. Book it as a recurring line item with a named owner. The version-matrix constraint (phpcent major ↔ Centrifugo major) means the two must be upgraded together in a single change, with staging verification, because the HTTP format changed across server majors.
Support. No commercial support for the library; Centrifugo has community channels and paid options for the server. Practically, you need one internal owner for the realtime platform who can read Centrifugo configuration and debug a token handshake. With 190 stars and a small maintainer set, assume you may need to patch or fork in a worst case — the codebase is small enough that this is a realistic fallback rather than a crisis.
Scaling. phpcent itself is stateless and scales horizontally with your app workers; it adds only the latency of an outbound HTTP call. Capacity planning belongs to Centrifugo: connection count, memory per connection, presence/history storage, and — beyond one node — a Redis or NATS engine for cross-node delivery. Keep publish calls out of the synchronous request path where possible; route through Laravel queues so a slow or degraded Centrifugo cannot back up user-facing requests. Tune both timeouts explicitly rather than relying on "never" semantics.
Failure modes to instrument.
forceIpResolveV4() for the documented IPv6 resolution timeout; certificate validation must stay on outside local development.Ramp-up. A competent Laravel engineer is productive with phpcent in hours — the API is a dozen method calls. The genuine learning curve is Centrifugo: token auth semantics, channel namespaces, engines, and the operational tuning above; budget days, not weeks, and pair it with the version matrix document. The frontend engineer needs a similar short spike on centrifuge-js connection lifecycle and token refresh. Total time-to-first-production-feature is measured in days for a low-risk notification path, provided the Centrifugo decision is made up front and the frontend workstream is resourced in the same plan rather than discovered in sprint three.
How can I help you explore Laravel packages today?