wsocket-io / sdk
wSocket Realtime Pub/Sub SDK for PHP
v0.1.0
2026-03-06 02:38 UTC
Requires
- php: >=8.1
- textalk/websocket: ^1.6
This package is not auto-updated.
Last update: 2026-03-07 02:14:10 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]);
Requirements
- PHP >= 8.1
textalk/websocket >= 1.6
Development
composer install
composer test
License
MIT