1、在vendor/workerman/文件夹下建立server.php文件,内容如下:

<?php
use Workerman\Worker;
require_once __DIR__ . '/workerman/Autoloader.php';
//如果使用ssl
$context = array( 'ssl' => array( // 请使用绝对路径 'local_cert' => '*.pem', // 也可以是crt文件 'local_pk' => '*.key', 'verify_peer' => false, // 'allow_self_signed' => true, //如果是自签名证书需要开启此选项 ), ); $ws_worker = new Worker("websocket://0.0.0.0:1234", $context); $ws_worker->count = 1; //启用内部通讯服务 $ws_worker->onWorkerStart = function ($ws_worker) { $context = array( 'ssl' => array( // 请使用绝对路径 'local_cert' => '*.pem', // 也可以是crt文件 'local_pk' => '*.key', 'verify_peer' => false, // 'allow_self_signed' => true, //如果是自签名证书需要开启此选项 ), ); $inner_text_worker = new Worker('Text://0.0.0.0:5678', $context); $inner_text_worker->onMessage = function ($connection_inner, $buffer) { global $ws_worker; foreach ($ws_worker->connections as $connection) { $connection->send($buffer); } $connection_inner->send($data); }; $inner_text_worker->listen(); }; Worker::runAll();

2、后台运行该文件

sudo nohup php ***/vendor/workerman/server.php start &

 

相关文章:

  • 2021-05-13
  • 2022-12-23
  • 2021-07-07
  • 2022-01-07
  • 2021-11-23
  • 2021-06-26
  • 2022-02-28
猜你喜欢
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-28
  • 2022-02-11
  • 2022-01-06
相关资源
相似解决方案