PHPackages                             iguazoft/yii2-sse-notification - 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. [Mail &amp; Notifications](/categories/mail)
4. /
5. iguazoft/yii2-sse-notification

ActiveYii2-extension[Mail &amp; Notifications](/categories/mail)

iguazoft/yii2-sse-notification
==============================

Yii2 Server-Sent Events &amp; Web Push Notification Extension

v1.0.0(4mo ago)00AGPL-3.0-or-laterPHPPHP &gt;=8.1

Since Feb 6Pushed 4mo agoCompare

[ Source](https://github.com/dannyrios81/yii2-sse-notification)[ Packagist](https://packagist.org/packages/iguazoft/yii2-sse-notification)[ RSS](/packages/iguazoft-yii2-sse-notification/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (4)Versions (2)Used By (0)

Yii2 SSE &amp; Web Push Notification Extension
==============================================

[](#yii2-sse--web-push-notification-extension)

Real-time notifications for Yii2 applications using Server-Sent Events (SSE) and Web Push (VAPID).

[![Latest Stable Version](https://camo.githubusercontent.com/50b4fe90999ee5f2cbdb0f85133fe107063324a186f8e39a606f8eb52a96de60/68747470733a2f2f706f7365722e707567782e6f72672f696775617a6f66742f796969322d7373652d6e6f74696669636174696f6e2f762f737461626c65)](https://packagist.org/packages/iguazoft/yii2-sse-notification)[![Total Downloads](https://camo.githubusercontent.com/53916969167554d30021672c7c3cb6ef0b54f3d005aa3748f9b7f556df6d197f/68747470733a2f2f706f7365722e707567782e6f72672f696775617a6f66742f796969322d7373652d6e6f74696669636174696f6e2f646f776e6c6f616473)](https://packagist.org/packages/iguazoft/yii2-sse-notification)[![License](https://camo.githubusercontent.com/1d86b6b57f1133dec370c990d166ba2d048c6edff1114b6f8a7b1eb64565c463/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4147504c2d2d332e30253230253246253230436f6d6d65726369616c2d626c7565)](https://packagist.org/packages/iguazoft/yii2-sse-notification)

Features
--------

[](#features)

- ✅ **Server-Sent Events (SSE)** - Real-time notifications for online users
- ✅ **Web Push Notifications (VAPID)** - Browser notifications for offline users
- ✅ **Automatic Routing** - Intelligently routes notifications via SSE or Web Push
- ✅ **Multiple Notification Types** - Private, authenticated broadcast, and public
- ✅ **Flexible Storage** - Redis and ActiveRecord drivers included
- ✅ **Service Worker** - Pre-configured for Web Push
- ✅ **Connection Management** - Automatic online/offline detection
- ✅ **Modern UI** - Toast notifications with customizable styling

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

[](#requirements)

- PHP &gt;= 8.1
- Yii2 &gt;= 2.0.14
- One of:
    - Redis (recommended for production)
    - MongoDB
    - MySQL/PostgreSQL (via ActiveRecord)

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

[](#installation)

Install via Composer:

```
composer require iguazoft/yii2-sse-notification
```

Quick Start
-----------

[](#quick-start)

### 1. Configure the Module

[](#1-configure-the-module)

Add the SSE module to your `config/web.php`:

```
'modules' => [
    'sse' => [
        'class' => 'iguazoft\sse\Module',
        'vapid' => [
            'subject' => 'mailto:admin@yourdomain.com',
            'publicKey' => 'YOUR_VAPID_PUBLIC_KEY',
            'privateKey' => 'YOUR_VAPID_PRIVATE_KEY',
        ],
    ],
],
```

### 2. Generate VAPID Keys

[](#2-generate-vapid-keys)

Generate your VAPID keys for Web Push:

```
# Using web-push CLI
npx web-push generate-vapid-keys

# Or using PHP
vendor/bin/web-push generate-vapid-keys
```

### 3. Configure Storage Driver

[](#3-configure-storage-driver)

Choose your notification storage driver in `config/web.php`:

**Option A: Redis (Recommended)**

```
'components' => [
    'redis' => [
        'class' => 'yii\redis\Connection',
        'hostname' => 'localhost',
        'port' => 6379,
        'database' => 0,
    ],
],
'container' => [
    'definitions' => [
        'iguazoft\sse\interfaces\NotificationSourceInterface' => [
            'class' => 'iguazoft\sse\drivers\RedisDriver',
        ],
    ],
],
```

**Option B: ActiveRecord (MySQL/PostgreSQL)**

```
'container' => [
    'definitions' => [
        'iguazoft\sse\interfaces\NotificationSourceInterface' => [
            'class' => 'iguazoft\sse\drivers\ActiveRecordDriver',
            'notificationClass' => 'app\models\Notification',
        ],
    ],
],
```

### 4. Run Database Migration

[](#4-run-database-migration)

Create the required tables:

```
php yii migrate --migrationPath=@vendor/iguazoft/yii2-sse/src/migrations
```

This creates:

- `notification` - Stores notifications (if using ActiveRecord)
- `push_subscription` - Stores Web Push subscriptions
- `user_connection` - Tracks online/offline status

### 5. Copy Service Worker

[](#5-copy-service-worker)

Copy the Service Worker to your web root:

```
cp vendor/iguazoft/yii2-sse/src/assets/sw.js web/sw.js
```

### 6. Add to Layout

[](#6-add-to-layout)

Include the SSE assets in your layout (`views/layouts/main.php`):

```
