1. Go to this page and download the library: Download hivellm/synap-sdk 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/ */
hivellm / synap-sdk example snippets
use Synap\SDK\SynapClient;
use Synap\SDK\SynapConfig;
// Create client — SynapRPC (the fastest transport) is the default scheme;
// resp3:// and http:// URLs are also accepted.
$config = SynapConfig::create('synap://localhost:15501');
$client = new SynapClient($config);
// Key-Value operations
$client->kv()->set('user:1', 'John Doe');
$value = $client->kv()->get('user:1');
echo "Value: {$value}\n";
// Queue operations
$client->queue()->createQueue('tasks');
$msgId = $client->queue()->publish('tasks', ['task' => 'process-video'], 9);
$message = $client->queue()->consume('tasks', 'worker-1');
if ($message) {
// Process message
$client->queue()->ack('tasks', $message->id);
}
// Event Stream
$client->stream()->createRoom('chat-room-1');
$offset = $client->stream()->publish('chat-room-1', 'message', [
'user' => 'alice',
'text' => 'Hello!',
]);
// Pub/Sub
$client->pubsub()->subscribeTopics('user-123', ['notifications.*']);
$delivered = $client->pubsub()->publish('notifications.email', [
'to' => '[email protected]',
'subject' => 'Welcome',
]);
use Synap\SDK\SynapConfig;
use Synap\SDK\SynapClient;
// SynapRPC — recommended default
$config = new SynapConfig('synap://127.0.0.1:15501');
$client = new SynapClient($config);
// RESP3 — Redis-compatible
$config = new SynapConfig('resp3://127.0.0.1:6379');
$client = new SynapClient($config);
// HTTP — full REST access
$config = new SynapConfig('http://127.0.0.1:15500');
$client = new SynapClient($config);
// All operations use this format internally:
POST /api/stream
{
"operation": "kv.set",
"target": "user:1",
"data": {
"value": "John Doe",
"ttl": 3600
}
}
bash
php examples/basic.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.