PHP code example of wireblob / wire
1. Go to this page and download the library: Download wireblob/wire 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/ */
wireblob / wire example snippets
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),
]);
$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',
]);
$wire->trigger('chat-room', 'new-message', [
'user' => 'Alice',
'message' => 'Hello everyone!',
]);
$wire->trigger([
'chat-room',
'notifications',
], 'system-update', [
'status' => 'ok',
]);
$wire->trigger('chat-room', 'new-message', [
'message' => 'Sent from the server',
], [
'socket_id' => '1234.5678',
]);
$wire->triggerBatch([
[
'channel' => 'chat-room',
'name' => 'new-message',
'data' => ['message' => 'Hello chat'],
],
[
'channel' => 'notifications',
'name' => 'ping',
'data' => ['ok' => true],
],
]);
$wire->sendToUser('user-123', 'inbox-update', [
'unread' => 4,
]);
$auth = $wire->authorizeChannel('private-chat-room', '1234.5678');
return response($auth, 200)
->header('Content-Type', 'application/json');
$auth = $wire->authorizePresenceChannel(
'presence-chat-room',
'1234.5678',
'user-123',
[
'name' => 'Alice',
'role' => 'member',
]
);
$channel = $wire->getChannelInfo('chat-room');
$channels = $wire->getChannels(['info' => 'connection_count']);
$users = $wire->getPresenceUsers('presence-chat-room');
$headers = getallheaders();
$body = file_get_contents('php://input');
$webhook = $wire->webhook($headers, $body);
foreach ($webhook->get_events() as $event) {
// Handle each event
}
$wire->verifySignature($headers, $body);
$wire->triggerAsync('chat-room', 'new-message', [
'message' => 'Queued from async flow',
])->then(function ($response) {
// Success
});
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
}