PHP code example of hivellm / thunder

1. Go to this page and download the library: Download hivellm/thunder 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 / thunder example snippets


use HiveLLM\Thunder\Client\Client;
use HiveLLM\Thunder\Client\ClientConfig;
use HiveLLM\Thunder\Client\Config;
use HiveLLM\Thunder\Client\Credentials;
use HiveLLM\Thunder\Client\ServerException;
use HiveLLM\Thunder\Wire\Value;

// Start from THE standard and add only your own identity. Everything else —
// handshake shape, frame cap, error convention — is the family default.
$config = Config::standard()->withScheme('myapp')->withPort(9000);

$client = Client::connect('myapp://localhost:9000', $config,
    (new ClientConfig())->withCredentials(Credentials::token('secret')));

try {
    echo $client->call('PING')->asStr();
} catch (ServerException $e) {
    // Branch on the class and the code, never on message text (CLT-052).
    error_log("server refused: {$e->errorCode}");
}

$a = $client->send('SLOW');   // written, not awaited
$b = $client->send('FAST');

echo $client->collect($b)->asStr();  // may complete first
echo $client->collect($a)->asStr();

$pool = new Pool('myapp://localhost:9000', $config);

$pool->with(function (Client $client): void {
    $client->call('SET', [Value::str('k'), Value::str('v')]);
    $client->call('GET', [Value::str('k')]);   // same connection
});