zoukankan      html  css  js  c++  java
  • thinkphp5自带workerman应用

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

    <?php
    use WorkermanWorker;
    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 &
  • 相关阅读:
    bzoj3574[Hnoi2014]抄卡组
    bzoj3576[Hnoi2014]江南乐
    [GDKOI2016]小学生数学题
    bzoj3572[Hnoi2014]世界树
    bzoj3571[Hnoi2014]画框
    bzoj3573[Hnoi2014]米特运输
    指数循环节
    bzoj4013[HNOI2015]实验比较
    bzoj4012[HNOI2015]开店
    bzoj1095[ZJOI2007]Hide 捉迷藏
  • 原文地址:https://www.cnblogs.com/dongqiliang/p/12553686.html
Copyright © 2011-2022 走看看