PHP code example of octamp / client

1. Go to this page and download the library: Download octamp/client 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/ */

    

octamp / client example snippets




use Octamp\Client\Auth\WampcraAuthenticator;
use Octamp\Client\Peer;
use Octamp\Client\Session;

sion $session) {
        // subscribe
        $session->subscribe('hello', function (array $args) {
            echo 'Event ' . $args[0] . PHP_EOL;
        });
    
        // publish
        $session->publish('hello', ['hello octamp'], [], ['exclude_me' => false]);
    
        // publish with acknowledgement
        $session
            ->publish('hello', ['hello octamp with acknowledgement'], [], ['acknowledge' => true, 'exclude_me' => false])
            ->then(
                function () {
                    echo 'Publish Acknowledged!' . PHP_EOL;
                },
                function ($error) {
                    echo 'Publish Error ' . $error . PHP_EOL;
                },
            );
    
        // register
        $session->register('add', function (array $args) {
            return $args[0] + $args[1];
        });
    
        // call
        $session->call('add', [1, 3])->then(function ($result) {
            echo 'Result ' . $result . PHP_EOL;
        });
    });
    
    $client->open();
});