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

Ably Php Laravel Laravel Package

ably/ably-php-laravel

Official Ably integration for Laravel. Adds an Ably broadcasting driver plus helpers for realtime pub/sub, presence, and token authentication, letting Laravel apps push live events to web and mobile clients over Ably’s globally distributed network.

View on GitHub
Deep Wiki
Context7

Getting Started

  • Install with composer require ably/ably-php-laravel. Laravel's package auto-discovery registers Ably\Laravel\AblyServiceProvider and the Ably facade alias, so no manual config/app.php edits are needed on Laravel 5.5+.
  • Publish the config: php artisan vendor:publish --provider="Ably\Laravel\AblyServiceProvider" (or --tag=config). This creates config/ably.php.
  • Set ABLY_KEY in .env using the full key string from your Ably dashboard: appId.keyId:keySecret. This is the single credential the package reads; there is no separate app-id setting to configure.
  • Look first at config/ably.php and at the service provider's container binding — the package is thin, essentially a singleton wrapper around Ably\AblyRest. Once you understand that binding, the rest of the API is the ably-php REST client, so the upstream ably-php docs are your real reference.
  • First use case: publish a message to a channel from a controller or event listener.
use Ably\Laravel\Facades\Ably;

Ably::channel('orders')->publish('created', ['id' => $order->id]);
  • Verify it works with a quick php artisan tinker call to Ably::time() — if that returns a timestamp, your key and network path are good and any remaining problem is channel/permission related.

Implementation Patterns

  • Controller publishing. Inject or facade-resolve the client and publish after a domain action. Wrap in a queued job or DB::afterCommit() so you never announce a message for a transaction that rolls back.
  • Queued broadcast job. For anything user-facing, publish from a ShouldQueue job rather than inline. This keeps request latency off the Ably round trip and gives you retries. Combine with ShouldBeUnique or a rate limiter to avoid flooding a channel during bulk operations.
  • Client-side auth via token requests. Do not ship the API key to the browser. Expose an endpoint that returns a token request and let the JS/PHP realtime client exchange it:
Route::get('/ably/auth', function () {
    return response()->json(
        Ably::auth()->createTokenRequest(['clientId' => auth()->id()])
    );
});

Scope the capability per channel (subscribe only, or publish for trusted clients) rather than granting blanket access.

  • Channel naming as a contract. Adopt a scheme like private-user.{id}, presence-room.{roomId}, org.{orgId}.events up front. The capability strings in your token endpoint must match these patterns exactly; retrofitting a naming scheme later means touching every auth rule.
  • Pair with Laravel broadcasting. For standard "broadcast this event" flows, Laravel's built-in ably broadcast driver (which also uses ably/ably-php) is usually the better fit — you get ShouldBroadcast events for free. Reach for this package's facade when you need direct REST control: presence queries, channel history, token requests, or publishing from non-broadcast contexts like console commands and webhooks.
  • Presence and history for server-side logic. Use Ably::channel($c)->presence->get() in dashboards and ->history() for backfill/replay endpoints, keeping in mind history is bounded by your account's retention settings.
  • Wrap the client. Bind your own AblyPublisher interface around the facade and inject that. It makes the package swappable and, more importantly, testable — see below.
  • Multi-tenant setups. If you serve several Ably apps, register named singleton instances with app()->instance() / a small factory rather than mutating the single bound client at runtime.

Gotchas and Tips

  • This package is not a broadcasting driver. It does not register a Broadcast::driver('ably'); that lives in the framework. Configuring BROADCAST_DRIVER=ably and expecting this package to handle it is a common first-day confusion.
  • REST only. The binding is AblyRest, not a realtime websocket client. There is no server-side subscribe callback here — inbound events must be consumed in the browser/JS client or via Ably's webhook/queue integrations. Design your architecture around that early.
  • Config caching. After changing ABLY_KEY in production, run php artisan config:cache (and config:clear locally). A stale cached key produces auth errors that look like a wrong credential.
  • Key format errors are opaque. A missing : or a key pasted with surrounding quotes surfaces as an AblyException at first call, not at boot. The package does no validation of the key at registration time — fail fast with your own boot-time check if a misconfiguration would be costly.
  • Testing. The client is a singleton hitting the network, so tests will make real HTTP calls unless you act. Either bind a mock AblyRest into the container in a test case, or (preferred) depend on your own wrapper interface and fake that. If you must assert on publish calls, a Mockery::mock(AblyRest::class) swapped via $this->app->instance() is the least invasive route.
  • Error handling. Calls throw Ably\Exceptions\AblyException with a code. Catch it in publish paths and decide whether a failed publish should fail the surrounding job — for user-triggered actions, swallowing and logging is often correct; for audit-style events, let it retry.
  • Version coupling. 1.0.8 is purely a dependency bump (ably-php 1.1.9), so nothing in your code changes. But it does mean the effective behavior of this package moves with upstream ably-php — pin ably/ably-php in composer.json if you need to control when SDK changes land, and check upstream release notes when bumping, since this package's own changelog won't mention them.
  • Rate limits and payload size. Ably enforces per-channel publish rates and a message size cap (typically 16 KiB). The SDK does not chunk for you; batch high-volume bursts and keep payloads small, sending IDs rather than full models where possible.
  • Extension point. The service provider's binding is the seam. If you need a custom-configured client (custom host, proxy, httpOptions, longer timeouts), rebind Ably\AblyRest in your own AppServiceProvider and the facade will resolve your instance — cleaner than post-hoc mutation of the singleton.
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.
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle
glavweb/extra-bundle
glavweb/api-bundle
glavweb/admin-bundle
adachsoft/api-version-bundle
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager