PHP code example of tourze / workerman-relay-worker

1. Go to this page and download the library: Download tourze/workerman-relay-worker 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/ */

    

tourze / workerman-relay-worker example snippets




use Tourze\Workerman\ConnectionPipe\Model\Address;
use Tourze\Workerman\RelayWorker\RelayWorker;
use Workerman\Connection\ConnectionInterface;

// Create a relay worker listening on a TCP port
$worker = new RelayWorker('tcp://0.0.0.0:8080');

// Set onConnect callback to establish the relay target
$worker->onConnect = function(ConnectionInterface $connection) {
    // Define target address for the connection
    $address = new Address('127.0.0.1', 9000, 'tcp');
    RelayWorker::setTarget($connection, $address);
};

// Start the worker
Worker::runAll();