PHP code example of neuralpin / notifyli

1. Go to this page and download the library: Download neuralpin/notifyli library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

neuralpin / notifyli example snippets



Neuralpin\Notifyli\Services\RedisMessageBroker;

// Initialize broker
$broker = new RedisMessageBroker(
    enabled: true,
    host: '127.0.0.1',
    port: 6379,
    password: null
);

// Send notification to specific user
$broker->publish(
    userId: 123,
    room: '/user/123',  // Private notification channel
    message: 'Your order #12345 has been shipped!',
    from: 'OrderSystem'
);

// Check if user is currently connected
if ($broker->isUserConnected(123, '/user/123')) {
    echo "User is online - notification delivered\n";
} else {
    echo "User is offline - notification queued\n";
}

use Neuralpin\Notifyli\Services\RedisMessageBroker;

$broker = new RedisMessageBroker(
    enabled: true,
    host: '127.0.0.1',
    port: 6379,
    password: null
);

// Publish notification
$broker->publish(userId: 123, room: '/user/123', message: 'Hello', from: 'System');

// Check user connection
$isConnected = $broker->isUserConnected(123, '/user/123');

// Get connection details
$info = $broker->getUserConnection(123, '/user/123');

┌─────────────────────────────────────────────────────────┐
│                    Nginx (Port 80/443)                  │
│  ┌──────────────────────┬───────────────────────────┐  │
│  │   Web UI (PHP-FPM)   │   WebSocket Proxy (7000)  │  │
│  │  public/index.php    │   → server.php daemon     │  │
│  └──────────────────────┴───────────────────────────┘  │
└─────────────────────────────────────────────────────────┘
                              │
                              ├──►  Redis Pub/Sub
                              │
                 ┌────────────┴────────────┐
                 │ notification-bridge.php │
                 │  (Notification Bridge)  │
                 └─────────────────────────┘