PHP code example of sejator / ws-server-php

1. Go to this page and download the library: Download sejator/ws-server-php 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/ */

    

sejator / ws-server-php example snippets




ejator\WebSocket\WsServer;

// Inisialisasi
$ws = new WsServer(
    'APP_KEY',               // App key
    'APP_SECRET',            // App secret
    'https://ws.example.com' // URL WebSocket server
);

// Publish event ke channel
$response = $ws->publish(
    'orders', // nama channel
    'order.created', // nama event
    [
        'order_id' => 123,
        'amount'   => 50000,
        'status'   => 'pending'
    ]
);

print_r($response);

publish(string $channel, string $event, array|string $data): array
txt
POST /api/events/{APP_KEY}
Content-Type: application/json
X-Signature: <signature>
X-Timestamp: <unix_timestamp>
txt
Application Backend (PHP)
        │
        │  sejator/ws-server-php
        │  (publish event)
        ▼
WebSocket Server
        │
        │  @sejator/ws-server
        ▼
Browser / Frontend
        │
        │  @sejator/ws-client
        ▼
Realtime Event Listener