PHP code example of spiral / roadrunner-broadcast

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

    

spiral / roadrunner-broadcast example snippets




use Spiral\Goridge\RPC\RPC;
use Spiral\RoadRunner\Broadcast\Broadcast;

e can send a message to a specific topic
//
$broadcast->publish('channel-1', 'message for channel #1');

// Now we can select the topic we need to work only with it
$topic = $broadcast->join(['channel-1', 'channel-2']);

// And send messages there
$topic->publish('message');
$topic->publish(['another message', 'third message']);
yaml
rpc:
  listen: tcp://127.0.0.1:6001

server:
  # Don't forget to create a "worker.php" file
  command: "php worker.php" 
  relay: "pipes"

http:
  address: 127.0.0.1:80
  # Indicate that HTTP support ws protocol
  middleware: [ "websockets" ]

websockets:
    broker: default
    path: "/ws"

broadcast:
    default:
        driver: memory
        config: {}