PHP code example of lowerpower / bolt

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

    

lowerpower / bolt example snippets


$loop = \React\EventLoop\Factory::create();

// other options like tls, socket, etc are possible see "React\Socket\Connector"
$options=$options=array(
    'timeout'=>5.0                      /* 'timeout'=> false for disable */
);

// Now workes exaction like "React\Socket\Connector" 
$client = new \Calcinai\Bolt\Client($loop, $options);

//Most WS servers will complain/forbid if there is no origin header
$client->setOrigin('127.0.0.1');

// new, URL is here, ws:// and wss:// supported
$client->connect('ws://127.0.0.1:1337/chat');

$client->on('stateChange', function($newState){
    echo "State changed to: $newState\n";
});

$client->on('message', function($message) use ($client){
    echo "New message: \n";
    echo $message;
    
    $client->send('This is a response message');
});

$loop->run();