Weave Code
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 for Centrifugo v5 HTTP API. Publish and broadcast to channels, manage subscriptions, presence and history, and run batch calls. Also generates JWT connection and subscription tokens. Composer-ready with configurable timeouts.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel Native Compatibility: The package is PHP-centric and Laravel-agnostic but integrates effortlessly with Laravel’s ecosystem. It uses cURL under the hood, which aligns with Laravel’s HTTP client abstractions (e.g., HttpClient facade or Guzzle integration). The Client class can be dependency-injected into Laravel services, controllers, or jobs, enabling clean separation of concerns.

    • Service Container: The package’s Client can be registered as a singleton in Laravel’s container, with configurable API keys/secrets via .env or config files.
    • Event System: Laravel’s event system can trigger real-time updates via phpcent (e.g., publish to a channel when an OrderCreated event fires).
    • Queue Integration: Heavy operations (e.g., batch publishes) can be queued using Laravel Queues, decoupling real-time logic from request handling.
  • Centrifugo Alignment: The package is tightly coupled to Centrifugo’s HTTP API (v5), which is a real-time messaging server optimized for pub/sub, presence, and push notifications. This fit is ideal for:

    • Pub/Sub Patterns: Laravel apps with event-driven architectures (e.g., notifications, live feeds).
    • Presence Tracking: Features like "online users" or collaborative editing.
    • Scalable WebSockets: Offload WebSocket management to Centrifugo, reducing Laravel’s load.
  • Anti-Patterns:

    • Not for Raw WebSocket Control: If the app needs to customize WebSocket protocols (e.g., binary framing, custom ping/pong), this package lacks low-level access.
    • No GraphQL/REST Hybrid: Centrifugo is WebSocket-first; if the app relies on HTTP polling or GraphQL subscriptions, additional abstraction may be needed.

Integration Feasibility

  • Low Friction: The package provides a simple API (publish, broadcast, generateToken, etc.) that maps directly to Centrifugo’s HTTP endpoints. Laravel’s facades or helpers can wrap phpcent for consistency.
    • Example:
      // Laravel Service Provider
      $this->app->singleton(\phpcent\Client::class, function ($app) {
          return new \phpcent\Client(
              config('centrifugo.api_url'),
              config('centrifugo.api_key'),
              config('centrifugo.secret_key')
          );
      });
      
  • Centrifugo Dependency: Requires a running Centrifugo instance (self-hosted or managed). Laravel’s config can centralize Centrifugo’s connection details (URL, keys, timeouts).
  • Authentication Flow:
    • API Key: For server-to-server calls (e.g., publishing messages).
    • JWT Tokens: For client connections (generated via generateConnectionToken/generateSubscriptionToken).
    • Laravel Sanctum/Passport: Can integrate with Laravel’s auth to auto-generate tokens for logged-in users.

Technical Risk

  • Centrifugo Version Lock: The package is v5-specific (as of 2026). Mismatches with Centrifugo’s API (e.g., upgrading to v6) may require package updates or manual patches.
    • Mitigation: Pin Centrifugo and phpcent versions in composer.json and monitor Centrifugo’s changelog.
  • Network Dependencies: Laravel’s performance is now tied to Centrifugo’s latency and uptime. Network issues (e.g., timeouts, DNS failures) may require circuit breakers or retries.
    • Mitigation: Use Laravel’s retry helpers or exponential backoff for HTTP calls.
  • Token Security: JWT tokens (for client connections) must be properly secured. Exposed secrets or weak TTLs risk unauthorized access.
    • Mitigation:
      • Store secrets in Laravel’s .env.
      • Use short-lived tokens (e.g., 5–30 minutes) with refresh mechanisms.
      • Validate tokens on the Centrifugo side (e.g., user ID claims).
  • Testing Complexity: Real-time systems require mocking WebSocket connections or integration tests with a live Centrifugo instance.
    • Mitigation: Use Laravel’s MockHttpClient or Dockerized Centrifugo for CI tests (as shown in the package’s README).

Key Questions

  1. Centrifugo Hosting:
    • Will Centrifugo be self-hosted (e.g., Kubernetes, Docker) or managed (e.g., Centrifugo Cloud)?
    • What are the SLA requirements for real-time updates (e.g., 99.9% uptime)?
  2. Authentication Strategy:
    • How will Laravel’s auth (e.g., Sanctum, Passport) integrate with Centrifugo tokens?
    • Will tokens be pre-signed (e.g., in API responses) or generated on-demand?
  3. Scaling Assumptions:
    • What is the expected peak concurrency (e.g., 10K vs. 1M WebSocket connections)?
    • Are there regional deployment needs (e.g., Centrifugo instances per AWS region)?
  4. Failure Modes:
    • How will the app handle Centrifugo outages (e.g., fallback to polling or queued retries)?
    • What monitoring/alerts are needed for Centrifugo’s health (e.g., connection drops, high latency)?
  5. Long-Term Maintenance:
    • Who will own Centrifugo updates (e.g., patching vulnerabilities, upgrading versions)?
    • Is there a backup plan if Centrifugo’s PHP client is deprecated or forked?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Service Container: Register phpcent\Client as a singleton with configurable options (e.g., timeouts, SSL).
    • Facades/Helpers: Create a Centrifugo facade to simplify usage (e.g., Centrifugo::publish('channel', $data)).
    • Events: Trigger phpcent publishes from Laravel events (e.g., OrderCreated → publish to orders.{user_id}).
    • Queues: Offload non-critical publishes to Laravel Queues (e.g., CentrifugoPublishJob).
  • Centrifugo Integration:
    • API Key: Store in config/centrifugo.php (e.g., api_key, secret_key, url).
    • JWT Generation: Extend Laravel’s auth to auto-generate tokens for users (e.g., middleware or service).
    • WebSocket Clients: Use Centrifugo’s JavaScript client (centrifuge/centrifuge) for frontend connections.

Migration Path

  1. Phase 1: Proof of Concept (1–2 weeks)
    • Set up a local Centrifugo instance (Docker) and phpcent.
    • Implement a single publish use case (e.g., notifications).
    • Test with Laravel’s Tinker or a minimal API endpoint.
  2. Phase 2: Core Integration (2–4 weeks)
    • Register phpcent\Client in Laravel’s container.
    • Add auth integration (e.g., Sanctum → Centrifugo tokens).
    • Implement error handling (retries, circuit breakers).
  3. Phase 3: Scaling and Optimization (Ongoing)
    • Add load testing (e.g., simulate 10K concurrent connections).
    • Optimize token generation (e.g., cache tokens, reduce TTL).
    • Set up monitoring (e.g., Centrifugo metrics in Prometheus).

Compatibility

  • Laravel Versions: Compatible with Laravel 9+ (PHP 8.1+). Tested with phpcent’s PHP 7.4+ requirement.
  • Centrifugo Versions: v5.x (as of 2026). Downgrade to phpcent v5.x if using Centrifugo v4.
  • Dependencies:
    • cURL: Required (enabled by default in PHP).
    • JWT Library: Uses PHP’s firebase/php-jwt for token generation (auto-installed via Composer).
    • SSL: Supports self-signed certs (setCert()) and disabled checks (setSafety(false)).

Sequencing

  1. Prerequisites:
    • Deploy Centrifugo (self-hosted or cloud).
    • Configure Laravel’s .env with Centrifugo credentials.
  2. Core Setup:
    • Install phpcent via Composer.
    • Register the Client in Laravel’s AppServiceProvider.
  3. Feature Rollout:
    • Basic Pub/Sub: Implement publish/broadcast for notifications.
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity