PHPackages                             artisan-build/resonance - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. artisan-build/resonance

ActiveLibrary[HTTP &amp; Networking](/categories/http)

artisan-build/resonance
=======================

Laravel package for beautiful Reverb, Pusher, Soketi, and Ably integration in pure PHP.

v0.1.1(5mo ago)679[1 issues](https://github.com/artisan-build/resonance/issues)MITPHPPHP ^8.4CI passing

Since Jan 18Pushed 5mo agoCompare

[ Source](https://github.com/artisan-build/resonance)[ Packagist](https://packagist.org/packages/artisan-build/resonance)[ Docs](https://github.com/artisan-build/resonance)[ GitHub Sponsors](https://github.com/artisan-build)[ RSS](/packages/artisan-build-resonance/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (13)Versions (4)Used By (0)

[![Resonance Logo](https://raw.githubusercontent.com/artisan-build/resonance/main/art/ChatGPT%20Image%20Jan%2016,%202026,%2009_01_17%20PM.png)](https://raw.githubusercontent.com/artisan-build/resonance/main/art/ChatGPT%20Image%20Jan%2016,%202026,%2009_01_17%20PM.png)

Resonance
=========

[](#resonance)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9fc25d30c312cc88176c151cafe18fd269608c8f8501595dd8d091429bb25e4a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6172746973616e2d6275696c642f7265736f6e616e63652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/artisan-build/resonance)[![GitHub Tests Action Status](https://camo.githubusercontent.com/894f1e0ef73baf72a79fe26104cd0bc80234a645671112df93fca8826533ace4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6172746973616e2d6275696c642f7265736f6e616e63652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/artisan-build/resonance/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ba9dcc5ce8476132a3665f9d983a7191f56387a08b461c7cb1e6afbf961e1f12/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6172746973616e2d6275696c642f7265736f6e616e63652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/artisan-build/resonance/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/7fdc9dd099bc6340233387c54ecdad10d46f6d814767715fcb6ed3e234983f8b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6172746973616e2d6275696c642f7265736f6e616e63652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/artisan-build/resonance)

Resonance is a Laravel WebSocket client for CLI commands, queue workers, and background processes. Inspired by Laravel Echo's API, it provides a familiar interface for real-time event listening—but from your PHP backend instead of the browser.

Built on [artisan-build/pusher-websocket-php](https://github.com/artisan-build/pusher-websocket-php) and ReactPHP's async event loop, Resonance connects to Reverb, Pusher, Soketi, and other Pusher-compatible servers.

Why Resonance?
--------------

[](#why-resonance)

Laravel Echo handles real-time features in the browser, but what about server-side PHP processes that need to listen for WebSocket events? Resonance fills that gap with:

- **Echo-inspired API** - Familiar `listen()`, `private()`, `join()` methods
- **Manager pattern** - Connect to multiple WebSocket servers simultaneously
- **Extensible drivers** - Add custom broadcasters with `extend()`
- **Laravel-native** - Config files, facades, and service providers out of the box

Installation
------------

[](#installation)

```
composer require artisan-build/resonance
```

You can publish the config file with:

```
php artisan vendor:publish --tag="resonance-config"
```

Configuration
-------------

[](#configuration)

Resonance follows Laravel's convention of defining connections in config and selecting via environment variable:

```
// config/resonance.php
return [
    'default' => env('RESONANCE_CONNECTION', 'reverb'),

    'connections' => [
        'reverb' => [
            'broadcaster' => 'reverb',
            'key' => env('REVERB_APP_KEY'),
            'authToken' => env('RESONANCE_AUTH_TOKEN'),
            'host' => env('REVERB_HOST', '127.0.0.1'),
            'port' => env('REVERB_PORT', 8080),
            'forceTLS' => env('REVERB_SCHEME', 'https') === 'https',
            'channelAuthorization' => [
                'endpoint' => env('APP_URL').'/broadcasting/auth',
            ],
        ],

        'pusher' => [
            'broadcaster' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'authToken' => env('RESONANCE_AUTH_TOKEN'),
            'cluster' => env('PUSHER_APP_CLUSTER', 'mt1'),
            'forceTLS' => true,
            'channelAuthorization' => [
                'endpoint' => env('APP_URL').'/broadcasting/auth',
            ],
        ],

        'null' => [
            'broadcaster' => 'null',
        ],
    ],

    'namespace' => 'App.Events',
];
```

### Configuration Options

[](#configuration-options)

OptionDescription`broadcaster`The broadcaster type: `reverb`, `pusher`, or `null``key`Your app key for the WebSocket server`authToken`Bearer token for channel authorization (e.g., Sanctum token)`host`WebSocket server hostname`port`WebSocket server port`forceTLS`Whether to use secure WebSocket (wss://)`cluster`Pusher cluster (for Pusher broadcaster)`channelAuthorization.endpoint`Full URL to your broadcasting auth endpoint> **Note:** The `authToken` is your authentication token (like a Laravel Sanctum token) used to authorize private/presence channel subscriptions. This is **not** the Reverb app secret—channel authorization is handled server-side where the signing secret lives.

Use `RESONANCE_CONNECTION=null` in your `.env.testing` to disable WebSocket connections during tests.

Usage
-----

[](#usage)

### Basic Channel Subscription

[](#basic-channel-subscription)

```
use ArtisanBuild\Resonance\Facades\Resonance;

// Using the default connection from config
$channel = Resonance::channel('orders');

$channel->listen('OrderShipped', function ($event) {
    echo "Order shipped: " . $event['order_id'];
});
```

### Multiple Connections

[](#multiple-connections)

Resonance uses the Manager pattern, allowing you to work with multiple connections:

```
use ArtisanBuild\Resonance\Facades\Resonance;

// Use a specific connection
Resonance::connection('reverb')->listen('orders', 'OrderShipped', function ($event) {
    // Handle internal events from your Reverb server
});

Resonance::connection('pusher')->listen('analytics', 'PageView', function ($event) {
    // Handle events from a third-party Pusher service
});
```

### Custom Drivers

[](#custom-drivers)

Extend Resonance with custom broadcasters:

```
use ArtisanBuild\Resonance\Facades\Resonance;

Resonance::extend('ably', function ($app, $config) {
    return new AblyConnector($config);
});
```

### Direct Instantiation

[](#direct-instantiation)

Or instantiate directly with custom options:

```
use ArtisanBuild\Resonance\Resonance;

$resonance = new Resonance([
    'broadcaster' => 'reverb',
    'key' => 'your-app-key',
    'authToken' => 'your-sanctum-token',
    'host' => '127.0.0.1',
    'port' => 8080,
    'forceTLS' => false,
    'channelAuthorization' => [
        'endpoint' => 'https://your-app.com/broadcasting/auth',
    ],
]);

$resonance->listen('orders', 'OrderShipped', function ($event) {
    echo "Order shipped: " . $event['order_id'];
});
```

### Private Channels

[](#private-channels)

```
// Subscribe to a private channel
$channel = $resonance->private('orders.123');

$channel->listen('OrderUpdated', function ($event) {
    // Handle the event
});
```

### Presence Channels

[](#presence-channels)

```
// Join a presence channel
$presence = $resonance->join('chat.room.1');

$presence->here(function ($users) {
    // Users currently in the channel
});

$presence->joining(function ($user) {
    // A user joined
});

$presence->leaving(function ($user) {
    // A user left
});

$presence->listen('NewMessage', function ($event) {
    // Handle chat message
});
```

### Connection Management

[](#connection-management)

```
// Register a callback for when connection is established
$resonance->connected(function () {
    echo "Connected to WebSocket server!";
});

// Get the socket ID (useful for excluding sender)
$socketId = $resonance->socketId();

// Leave a specific channel
$resonance->leave('orders');

// Leave a single channel variant
$resonance->leaveChannel('private-orders.123');

// Disconnect entirely
$resonance->disconnect();
```

### Encrypted Private Channels

[](#encrypted-private-channels)

```
$channel = $resonance->encryptedPrivate('sensitive-data');

$channel->listen('SecretEvent', function ($event) {
    // Decrypted event data
});
```

Real-World Example: CLI Chat with Community Prompts
---------------------------------------------------

[](#real-world-example-cli-chat-with-community-prompts)

Here's a real-time chat application built with `AsyncPrompt` from [artisan-build/community-prompts](https://github.com/artisan-build/community-prompts), demonstrating how Resonance enables interactive CLI tools:

```
