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

Phpcent Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

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.

  • Version lockstep (medium). phpcent 6 ↔ Centrifugo 5; phpcent 5.x ↔ Centrifugo 4; 4.x ↔ Centrifugo 3. The HTTP wire format changed between server majors. Upgrading one without the other breaks publishing and, worse, token generation. This is a permanent operational constraint, not a one-time setup task.
  • Silent failure (medium-high). API methods return response payloads rather than throwing on server-side errors. Uninspected responses mean dropped messages that surface as user complaints, not exceptions or alerts. This must be wrapped and logged on day one.
  • Secret handling (medium). The client holds an API key and a signing secret; both must live in a secret store, never in config/*.php or the repository. Token forgery is the blast radius of a leaked secret.
  • Misconfiguration footguns (low-medium). 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.
  • Vendor concentration (low). MIT, official client from the Centrifugo team, released in step with the server. But it is a small, two-to-three-maintainer library with a modest footprint and near-zero listed dependents — it will not clear a strict "widely adopted" procurement bar, even though the maintenance signal is good.
  • Not a differentiator (informational). The library is genuinely thin; the strategic decision is Centrifugo adoption, and the strategic cost is operating a stateful service, not writing PHP.

Key questions.

  1. Which Centrifugo major version do we standardize on, and where is that recorded as an infrastructure dependency with an upgrade owner? 2What is the channel authorization model — public channels (fast to ship, hard to retrofit) or private per-user channels via subscription tokens (safe to ship)? Decide before launch; changing later is a breaking change for clients.
  2. Self-hosted Centrifugo or a managed provider (Pusher/Ably/Firebase)? This package presupposes self-hosted, and choosing otherwise invalidates the integration entirely.
  3. Do we actually need presence, history, and channels, or only publish? Presence and history carry memory and storage costs on the server and materially change capacity planning.
  4. Where does the frontend workstream sit — who owns centrifuge-js, the token endpoint contract, reconnect/backoff behavior, and the handshake test?
  5. What is the delivery SLO for a published message, and should publishing happen inline in the request path or exclusively from queued jobs?
  6. Does any consumer already assume polling, and what is the cutover story?

Integration Approach

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.

  1. Decision gate: self-hosted vs. managed provider; if self-hosted, fix the Centrifugo major version.
  2. Stand up Centrifugo in staging (Docker image is the documented path) with API key, JWT secret, allowed origins, channel namespaces, and presence/history enabled only for channels that need them.
  3. Add the dependency, container binding, and the RealtimePublisher wrapper with response inspection, structured logging, and metrics.
  4. Build the token endpoint and a frontend handshake spike — this is the highest-uncertainty item and should be de-risked before broad backend work.
  5. Instrument one publish path (a queued job) behind a flag; validate latency, error rate, and reconnect behavior under a small load test.
  6. Expand to remaining channels and features (notifications, presence, live dashboards) in value order.
  7. Write the upgrade runbook: version matrix, key rotation procedure, rollback steps.

Operational Impact

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.

  • Dropped messages with no exception. The dominant risk. Inspect every response, count errors, alert on non-zero.
  • Timeout cascades. Under load or network partition, cURL calls block workers. Set a bounded request timeout and fail fast.
  • Credential failure. Rotated API key or JWT secret breaks publishing or token issuance abruptly; expiry of tokens in flight logs users out. Rotate deliberately, with overlap.
  • TLS/DNS incidents. forceIpResolveV4() for the documented IPv6 resolution timeout; certificate validation must stay on outside local development.
  • Version drift. A server upgrade ahead of the client produces 400/404 responses that read like application bugs.
  • Resource exhaustion. Presence and history enabled on high-cardinality channels are the usual cause of Centrifugo memory growth and OOM restarts.
  • Reconnect storms. A restarting Centrifugo produces a thundering herd from clients; this is a frontend/serving concern, but it will be reported as "the realtime feature is broken" and you should own the runbook.

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.

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