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

Pusher Php Server Laravel Package

pusher/pusher-php-server

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install via Composer: composer require pusher/pusher-php-server.
  2. Instantiate the Pusher\Pusher client using your Pusher app credentials (APP_ID, KEY, SECRET, CLUSTER).
  3. Trigger an event: $pusher->trigger('my-channel', 'my-event', 'Hello world');.
  4. For Laravel, configure broadcasting via config/broadcasting.php and use Broadcast::event() or event(new SomethingWasCreated) with Laravel’s built-in Pusher driver.

Implementation Patterns

  • Triggering events synchronously: For fire-and-forget notifications (e.g., after database writes), use trigger() inside service layers.
  • Batching events: Group related events using triggerBatch() to reduce HTTP overhead (e.g., send 10 channel updates in one call).
  • Asynchronous triggers: Use triggerAsync() + Guzzle promises for non-blocking side effects (e.g., notify frontend without delaying HTTP response).
  • Authenticating users:
    • Private channels: authorizeChannel('private-ch', $socketId)
    • Presence channels: authorizePresenceChannel('presence-ch', $socketId, $userId, ['name' => $user->name])
    • Return JSON response with auth key and optionally channel_data/user_data.
  • Webhook verification: Use $pusher->webhook($headers, $body) to validate and parse incoming Pusher webhook payloads (e.g., for analytics or audit logging).
  • Channel introspection: Call getChannelInfo() or getChannels() to display active users/channels in admin dashboards or real-time analytics.

Gotchas and Tips

  • Double JSON encoding: Avoid json_encode() on event data — the library handles serialization. Pass raw arrays/objects.
  • Socket ID exclusion: Always pass socket_id when triggering from a user’s own session to avoid echoing back to them.
  • Encrypted channels: Only prefix with private-encrypted- for end-to-end encryption. Mixing encrypted/unencrypted in same trigger() call throws an error.
  • Async caveats: triggerAsync() returns a Guzzle promise — remember to ->wait() only when needed (e.g., in CLI jobs), not in HTTP requests.
  • HTTP options: Set timeout, useTLS, or custom host carefully — proxy setups may require path.
  • PSR-3 logging: Inject your logger via setLogger() for visibility into HTTP retries, rate limits, or auth failures.
  • Laravel gotcha: Ensure PUSHER_APP_CLUSTER is set in .env; otherwise, channels may silently fail.
  • Testing: Mock Pusher\Pusher in unit tests or use MockHandler with custom Guzzle client for integration tests.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport