PHPackages                             amarwave/amarwave-php - 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. amarwave/amarwave-php

ActiveLibrary

amarwave/amarwave-php
=====================

Official PHP client for AmarWave real-time messaging. Works with raw PHP, Laravel, Symfony, or any PHP framework.

00PHP

Since Apr 4Pushed yesterdayCompare

[ Source](https://github.com/amarwave/amarwave-php)[ Packagist](https://packagist.org/packages/amarwave/amarwave-php)[ RSS](/packages/amarwave-amarwave-php/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

amarwave-php
============

[](#amarwave-php)

Official PHP client for [AmarWave](https://github.com/amarwave/amarwave) real-time messaging.

Works in **any PHP environment** — raw PHP, Laravel, Symfony, or any other framework.

For Laravel projects, a **service provider**, **facade**, and **broadcasting driver** are included automatically.

---

Requirements
------------

[](#requirements)

- PHP 8.1+
- `ext-curl`
- `ext-json`
- Laravel 10, 11, or 12 *(optional — only needed for the Laravel integration)*

---

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

[](#installation)

```
composer require amarwave/amarwave-php
```

Laravel auto-discovers the service provider and facade via `composer.json`.

---

Usage — Raw PHP
---------------

[](#usage--raw-php)

```
use AmarWave\AmarWave;
use AmarWave\AmarWaveException;

$aw = new AmarWave(
    appKey:    'your-app-key',
    appSecret: 'your-app-secret',
    cluster:   'default',
);

// Trigger a single event
$aw->trigger('orders', 'placed', ['order_id' => 42]);

// Trigger multiple events in one request
$aw->triggerBatch([
    ['channel' => 'chat-1', 'event' => 'message', 'data' => ['text' => 'Hello']],
    ['channel' => 'chat-2', 'event' => 'message', 'data' => ['text' => 'World']],
]);
```

### Error handling

[](#error-handling)

```
use AmarWave\AmarWaveException;

try {
    $aw->trigger('channel', 'event', $data);
} catch (AmarWaveException $e) {
    $status = $e->getStatusCode();
    $body   = $e->getResponseBody();
    echo "AmarWave {$status}: {$e->getMessage()}";
}
```

---

Usage — Laravel
---------------

[](#usage--laravel)

### Configuration

[](#configuration)

Publish the config file:

```
php artisan vendor:publish --tag=amarwave-config
```

Add to your `.env`:

```
AMARWAVE_APP_KEY=your-app-key
AMARWAVE_APP_SECRET=your-app-secret
AMARWAVE_CLUSTER=default
AMARWAVE_TIMEOUT=10
```

### Facade

[](#facade)

```
use AmarWave\Laravel\AmarWaveFacade as AmarWave;

AmarWave::trigger('orders', 'placed', ['order_id' => 42]);

AmarWave::triggerBatch([
    ['channel' => 'chat-1', 'event' => 'message', 'data' => ['text' => 'Hello']],
    ['channel' => 'chat-2', 'event' => 'message', 'data' => ['text' => 'World']],
]);
```

Or with the global alias:

```
\AmarWave::trigger('orders', 'placed', ['order_id' => 42]);
```

### Dependency Injection

[](#dependency-injection)

```
use AmarWave\AmarWave;

class OrderController extends Controller
{
    public function __construct(private readonly AmarWave $aw) {}

    public function store(Request $request): JsonResponse
    {
        $order = Order::create($request->validated());
        $this->aw->trigger('orders', 'placed', $order->toArray());
        return response()->json($order, 201);
    }
}
```

### Broadcasting Driver

[](#broadcasting-driver)

Use AmarWave as a Laravel broadcasting driver so `broadcast(new YourEvent)` works out of the box.

**1 — Add the connection to `config/broadcasting.php`**

```
'connections' => [
    'amarwave' => [
        'driver' => 'amarwave',
    ],
    // ...existing drivers
],
```

**2 — Set the driver in `.env`**

```
# Laravel 10
BROADCAST_DRIVER=amarwave
# Laravel 11+
BROADCAST_CONNECTION=amarwave
```

**3 — Create a broadcastable event**

```
namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class OrderPlaced implements ShouldBroadcast
{
    public function __construct(public readonly array $order) {}

    public function broadcastOn(): array
    {
        return [
            new Channel('orders'),
            new PrivateChannel("user.{$this->order['user_id']}"),
        ];
    }

    public function broadcastAs(): string { return 'order.placed'; }

    public function broadcastWith(): array
    {
        return ['order_id' => $this->order['id'], 'total' => $this->order['total']];
    }
}
```

**4 — Dispatch**

```
broadcast(new OrderPlaced($order));
```

### Channel Authorization

[](#channel-authorization)

In `routes/channels.php`:

```
use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('user.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});

Broadcast::channel('presence-room.{roomId}', function ($user, $roomId) {
    $room = \App\Models\Room::find($roomId);
    if ($room?->members()->where('user_id', $user->id)->exists()) {
        return ['id' => $user->id, 'name' => $user->name];
    }
    return false;
});
```

---

License
-------

[](#license)

MIT

###  Health Score

20

—

LowBetter than 15% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/03a4f26e2aaf1750564c6efd488157ca5ee58c8292197fe611d13833aa36db3c?d=identicon)[fnnaeem](/maintainers/fnnaeem)

---

Top Contributors

[![fnnaeem1881](https://avatars.githubusercontent.com/u/77448606?v=4)](https://github.com/fnnaeem1881 "fnnaeem1881 (6 commits)")

### Embed Badge

![Health badge](/badges/amarwave-amarwave-php/health.svg)

```
[![Health](https://phpackages.com/badges/amarwave-amarwave-php/health.svg)](https://phpackages.com/packages/amarwave-amarwave-php)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
