wireblob / wire
Library for interacting with the Wireblob Socket API, providing real-time messaging and event handling capabilities.
Requires
- php: ^7.3|^8.0
- ext-curl: *
- ext-json: *
- guzzlehttp/guzzle: ^7.2
- psr/log: ^1.0|^2.0|^3.0
Requires (Dev)
- overtrue/phplint: ^2.3
- phpunit/phpunit: ^9.3
README
Server-side PHP SDK for Wireblob, a realtime platform for publishing events, authorizing private and presence channels, inspecting channel state, and validating webhooks.
This package is heavily aligned with the Pusher PHP server SDK and is intended to be Wireblob-friendly out of the box. If you are migrating from a Pusher-style integration, the API surface should feel familiar.
Features
- Publish events to one or many channels
- Trigger batch events
- Authorize private, presence, and encrypted channels
- Fetch channel and presence information
- Validate and parse webhook payloads
- Keep compatibility with existing Pusher-style server integrations
Requirements
- PHP
^7.3|^8.0 ext-curlext-json
Installation
composer require wireblob/wire
Quick start
<?php use Wireblob\Wire; $wire = new Wire( 'your-application-key', 'your-application-secret', 'your-application-id', [ 'host' => 'eu-central-1.wireblob.com', 'scheme' => 'https', 'useTLS' => true, ] ); $wire->trigger('chat-room', 'new-message', [ 'user' => 'Alice', 'message' => 'Hello everyone!', 'timestamp' => date(DATE_ATOM), ]);
Configuration
The Wire constructor accepts your app credentials and an optional configuration array:
$wire = new Wire($key, $secret, $appId, [ 'host' => 'eu-central-1.wireblob.com', 'scheme' => 'https', 'port' => 443, 'path' => '', 'timeout' => 30, 'useTLS' => true, 'cluster' => 'mt1', 'encryption_master_key_base64' => 'base64-encoded-32-byte-key', ]);
Common options
host: Wireblob API host for your regionscheme:httporhttpsport: API porttimeout: request timeout in secondsuseTLS: whentrue, defaults to HTTPS on port443cluster: Pusher-style cluster fallbackencryption_master_key_base64: required for encrypted channel authorization and webhook decryption
For Wireblob deployments, you will usually want to set
hostexplicitly.
Publishing events
Trigger a single event
$wire->trigger('chat-room', 'new-message', [ 'user' => 'Alice', 'message' => 'Hello everyone!', ]);
Trigger to multiple channels
$wire->trigger([ 'chat-room', 'notifications', ], 'system-update', [ 'status' => 'ok', ]);
Exclude the sender with socket_id
$wire->trigger('chat-room', 'new-message', [ 'message' => 'Sent from the server', ], [ 'socket_id' => '1234.5678', ]);
Trigger a batch of events
$wire->triggerBatch([ [ 'channel' => 'chat-room', 'name' => 'new-message', 'data' => ['message' => 'Hello chat'], ], [ 'channel' => 'notifications', 'name' => 'ping', 'data' => ['ok' => true], ], ]);
Send an event directly to a user
$wire->sendToUser('user-123', 'inbox-update', [ 'unread' => 4, ]);
Channel authorization
Use the authorization helpers in your private or presence channel auth endpoint.
Private channel
$auth = $wire->authorizeChannel('private-chat-room', '1234.5678'); return response($auth, 200) ->header('Content-Type', 'application/json');
Presence channel
$auth = $wire->authorizePresenceChannel( 'presence-chat-room', '1234.5678', 'user-123', [ 'name' => 'Alice', 'role' => 'member', ] );
Compatibility aliases
For projects coming from the Pusher SDK, the following compatibility methods are also available:
socketAuth()presenceAuth()
The preferred method names are:
authorizeChannel()authorizePresenceChannel()
Channels and presence
$channel = $wire->getChannelInfo('chat-room'); $channels = $wire->getChannels(['info' => 'connection_count']); $users = $wire->getPresenceUsers('presence-chat-room');
Webhooks
You can verify webhook signatures and parse webhook payloads from Wireblob.
$headers = getallheaders(); $body = file_get_contents('php://input'); $webhook = $wire->webhook($headers, $body); foreach ($webhook->get_events() as $event) { // Handle each event }
If you only need to validate the signature:
$wire->verifySignature($headers, $body);
Async operations
Async variants are available when you want to work with Guzzle promises:
triggerAsync()triggerBatchAsync()sendToUserAsync()terminateUserConnectionsAsync()
Example:
$wire->triggerAsync('chat-room', 'new-message', [ 'message' => 'Queued from async flow', ])->then(function ($response) { // Success });
Error handling
The SDK may throw:
Wireblob\WireExceptionfor validation, signing, or payload issuesWireblob\ApiErrorExceptionwhen the API returns an error responseGuzzleHttp\Exception\GuzzleExceptionfor HTTP client failures
Example:
try { $wire->trigger('chat-room', 'new-message', ['message' => 'Hello']); } catch (\Wireblob\ApiErrorException $e) { // API returned an error response } catch (\Wireblob\WireException $e) { // SDK validation or signing error }
Notes for Pusher users
- The SDK API is intentionally close to the Pusher PHP server SDK
- Wireblob-specific deployments should use your Wireblob host, for example
eu-central-1.wireblob.com - Compatibility headers for Pusher-style integrations are still present in requests and webhook validation
License
MIT