PHPackages                             meita/realtime-notifications - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. meita/realtime-notifications

ActiveLibrary[File &amp; Storage](/categories/file-storage)

meita/realtime-notifications
============================

Fast, reliable realtime notifications over SSE backed by JSON/TXT files in storage (per user\_id).

1.0.0(4mo ago)09MITPHPPHP ^8.1

Since Dec 20Pushed 4mo agoCompare

[ Source](https://github.com/EngMEita/notifications)[ Packagist](https://packagist.org/packages/meita/realtime-notifications)[ RSS](/packages/meita-realtime-notifications/feed)WikiDiscussions main Synced 1mo ago

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

meita/realtime-notifications
============================

[](#meitarealtime-notifications)

**Author:** Mohamed A. Eita ()

File-backed, reliable realtime notifications over **Server-Sent Events (SSE)**. Notifications are stored per `user_id` as **JSON/TXT** under `storage`, moved to `inflight/` when streamed, and **deleted after ACK**.

Works standalone in pure PHP or plugged into Laravel (10/11/12). Comes with a Laravel bridge (routes + provider) and a plain PHP adapter.

---

Features
--------

[](#features)

- SSE push (`event: meita.notification`) with auto ACK support
- Storage as files: JSON (structured) or TXT (plain)
- Per user folders: `meita/notifications/{pending|inflight}/{userId}/...`
- Keyword filtering for JSON (`?keywords=order,urgent`)
- Lease handling: pending → inflight until ACK; reclaim stale inflight files
- Auth via signed token (or Laravel auth/session when using the bridge)

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

[](#requirements)

- PHP `^8.1`
- Optional Laravel bridge: Laravel `^10|^11|^12`

Install
-------

[](#install)

```
composer require meita/realtime-notifications
```

For a local path repo (adjust the path as needed):

```
{
  "repositories": [
    { "type": "path", "url": "../realtime-notifications", "options": { "symlink": true } }
  ],
  "require": { "meita/realtime-notifications": "*" }
}
```

Storage layout
--------------

[](#storage-layout)

```
storage/app/meita/notifications/
  pending/{userId}/
  inflight/{userId}/

```

Flow: push → pending → stream moves to inflight → ACK deletes.

Usage with Laravel
------------------

[](#usage-with-laravel)

1. Install the package (auto-discovery registers the provider and facade).
2. Optional publish:

```
php artisan vendor:publish --tag=meita-notifications-config
php artisan vendor:publish --tag=meita-notifications-assets --force
```

### Push from PHP

[](#push-from-php)

```
use Meita\RealtimeNotifications\Facades\MeitaNotifications;

MeitaNotifications::push(42, 'Order created successfully', [
    'title' => 'Orders',
    'type' => 'success',
    'keywords' => ['order', 'payments'],
    'data' => ['order_id' => 999],
    'format' => 'json', // or 'txt'
    'ttl_seconds' => 3600,
]);
```

### Generate a token (for SSE/ACK)

[](#generate-a-token-for-sseack)

```
$token = MeitaNotifications::tokenForUser(42);
```

### Endpoints (provided by the bridge)

[](#endpoints-provided-by-the-bridge)

- Stream (SSE): `GET /api/meita/notifications/stream/{userId}?meita_token=...`
- ACK: `POST /api/meita/notifications/ack/{userId}?meita_token=...`

### Browser (vanilla JS)

[](#browser-vanilla-js)

```

  const userId = 42;
  const token = 'PUT_TOKEN_HERE';
  const streamUrl = `/api/meita/notifications/stream/${userId}?meita_token=${encodeURIComponent(token)}`;
  const ackUrl = `/api/meita/notifications/ack/${userId}?meita_token=${encodeURIComponent(token)}`;

  const es = new EventSource(streamUrl);
  es.addEventListener('meita.notification', async (event) => {
    const n = JSON.parse(event.data);
    console.log('NOTIF', n);
    await fetch(ackUrl, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ file: n.file, id: n.id }),
    });
  });

```

### Using the shipped JS client

[](#using-the-shipped-js-client)

```
php artisan vendor:publish --tag=meita-notifications-assets --force
```

```

  import { MeitaNotificationsClient } from '/vendor/meita/meita-notifications.js';
  const userId = 42;
  const token = 'PUT_TOKEN_HERE';
  const client = new MeitaNotificationsClient({
    userId,
    streamUrl: `/api/meita/notifications/stream/${userId}?meita_token=${encodeURIComponent(token)}`,
    ackUrl: `/api/meita/notifications/ack/${userId}?meita_token=${encodeURIComponent(token)}`,
    onNotification: async (n) => console.log('NOTIF', n),
    onError: (e) => console.error('SSE error', e),
  });
  client.connect();

```

Usage in pure PHP (or any framework)
------------------------------------

[](#usage-in-pure-php-or-any-framework)

Use the core manager with the local filesystem adapter:

```
use Meita\RealtimeNotifications\Adapters\LocalFilesystemAdapter;
use Meita\RealtimeNotifications\MeitaNotificationsManager;

$config = [
    'disk_root' => __DIR__.'/storage',       // where files are stored
    'base_dir' => 'meita/notifications',
    'secret_key' => 'base64:your-key-or-plain-string',
    'auth' => ['token_ttl_seconds' => 3600],
];

$manager = new MeitaNotificationsManager(
    $config,
    new LocalFilesystemAdapter($config['disk_root'])
);

// push
$ref = $manager->push('user-123', 'Hello standalone', ['keywords' => ['demo']]);

// token (sign/verify yourself in your HTTP layer)
$token = $manager->tokenForUser('user-123');
```

Build your own HTTP endpoints (any framework) mirroring the Laravel controllers:

- SSE stream: emit `event: meita.notification` with JSON payload from `reserveNext(...)`, move file to inflight, `flush()`, heartbeat `: ping`.
- ACK: delete by `file` or `id` using `$manager->store()->ackMany(...)`.

Configuration (ENV for Laravel bridge)
--------------------------------------

[](#configuration-env-for-laravel-bridge)

```
MEITA_NOTIFICATIONS_DISK=local
MEITA_NOTIFICATIONS_BASE_DIR=meita/notifications
MEITA_NOTIFICATIONS_SECRET=base64:...or key...
MEITA_NOTIFICATIONS_AUTH_MODE=token_or_auth   # token_or_auth | token | auth | none
MEITA_NOTIFICATIONS_TOKEN_TTL=3600
MEITA_NOTIFICATIONS_TOKEN_PARAM=meita_token
MEITA_NOTIFICATIONS_SSE_RETRY_MS=2000
MEITA_NOTIFICATIONS_POLL_MS=500
MEITA_NOTIFICATIONS_HEARTBEAT_SECONDS=15
MEITA_NOTIFICATIONS_LEASE_TTL_SECONDS=30
MEITA_NOTIFICATIONS_RECLAIM_ON_STREAM_START=true

```

Tests
-----

[](#tests)

```
composer install
composer test
```

Tests are under `tests/Feature/MeitaRealtimeNotificationsTest.php`.

License
-------

[](#license)

MIT

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance74

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

143d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5915383ac10e7c148c23e142195199c8e7909acc2cda2003c26e688090956014?d=identicon)[EngMEita](/maintainers/EngMEita)

---

Top Contributors

[![EngMEita](https://avatars.githubusercontent.com/u/11925529?v=4)](https://github.com/EngMEita "EngMEita (1 commits)")

---

Tags

phpjsonlaravelnotificationsfilestoragesserealtimeeventsourcetxtmeita

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/meita-realtime-notifications/health.svg)

```
[![Health](https://phpackages.com/badges/meita-realtime-notifications/health.svg)](https://phpackages.com/packages/meita-realtime-notifications)
```

###  Alternatives

[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.3M74](/packages/unisharp-laravel-filemanager)[qruto/laravel-wave

Painless Laravel Broadcasting with SSE.

87048.4k](/packages/qruto-laravel-wave)[sopamo/laravel-filepond

Laravel backend module for filepond uploads

215272.2k3](/packages/sopamo-laravel-filepond)[soarecostin/file-vault

192195.0k](/packages/soarecostin-file-vault)[djurovicigoor/lara-files

Lara-files is a package which will make it easier to work with files. Package has built-in support for DigitalOcean spaces and Amazon S3.

1196.5k](/packages/djurovicigoor-lara-files)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)

PHPackages © 2026

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