wsocket-io / sdk
wSocket Realtime Pub/Sub SDK for PHP
v0.2.0
2026-03-08 08:16 UTC
Requires
- php: >=8.1
- textalk/websocket: ^1.6
This package is not auto-updated.
Last update: 2026-05-16 03:10:24 UTC
README
Official PHP SDK for wSocket — Realtime Pub/Sub over WebSockets.
Installation
composer require wsocket-io/sdk
Quick Start
<?php require 'vendor/autoload.php'; $client = new \wSocket\Client('wss://node00.wsocket.online', 'your-api-key'); $client->connect(); $chat = $client->channel('chat:general'); $chat->subscribe(function ($data, $meta) { echo "[{$meta['channel']}] " . json_encode($data) . "\n"; }); $chat->publish(['text' => 'Hello from PHP!']); $client->listen(); // blocking event loop
Features
- Pub/Sub — Subscribe and publish to channels in real-time
- Presence — Track who is online in a channel
- History — Retrieve past messages
- Connection Recovery — Automatic reconnection with message replay
Presence
$chat = $client->channel('chat:general'); $chat->presence()->onEnter(function ($member) { echo "Joined: {$member['clientId']}\n"; }); $chat->presence()->onLeave(function ($member) { echo "Left: {$member['clientId']}\n"; }); $chat->presence()->enter(['name' => 'Alice']); $members = $chat->presence()->get();
History
$chat->onHistory(function ($result) { foreach ($result['messages'] as $msg) { echo "[{$msg['timestamp']}] " . json_encode($msg['data']) . "\n"; } }); $chat->history(['limit' => 50]);
Push Notifications
$push = new \WSocketIO\PushClient('https://your-server.com', 'your-api-key', 'your-app-id'); // Register & send $push->registerFCM('device-token', 'user-123'); $push->sendToMember('user-123', ['title' => 'Hello', 'body' => 'World']); $push->broadcast(['title' => 'News']); // Channel targeting $push->addChannel('subscription-id', 'alerts'); $push->removeChannel('subscription-id', 'alerts'); // VAPID key & subscriptions $vapidKey = $push->getVapidKey(); $subs = $push->listSubscriptions('user-123');
Requirements
- PHP >= 8.1
textalk/websocket >= 1.6
Development
composer install
composer test
License
MIT