国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

ThinkPHP6中使用GatewayWorker

這篇具有很好參考價(jià)值的文章主要介紹了ThinkPHP6中使用GatewayWorker。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

首先是先安裝

composer require workerman/gateway-worker
composer require workerman/gatewayclient

下載demo

服務(wù)器開通TCP端口8282、1238

Applications\YourApp目錄隨便放ThinkPHP6的哪個(gè)位置,我這里放在了app\gateway\ws目錄中
配置composer.json

"autoload": {
    "psr-4": {
      "app\\": "app",
      "": "app/gateway/ws" # 增加這一行
    },
    "psr-0": {
      "": "extend/"
    }
  },

保存后執(zhí)行composer dumpautoload更新

Events.php、start_businessworker.php、start_gateway.phpstart_register.php文件中的require_once __DIR__ . '/../../vendor/autoload.php';刪除

修改start_gateway.php文件,設(shè)置ssl

// 證書最好是申請(qǐng)的證書
$context = array(
    // 更多ssl選項(xiàng)請(qǐng)參考手冊(cè) https://php.net/manual/zh/context.ssl.php
    'ssl' => array(
        // 請(qǐng)使用絕對(duì)路徑
        'local_cert' => '/www/wwwroot/xxx.xxx.com/app/gateway/ws/ssl/server.pem', // 也可以是crt文件
        'local_pk' => '/www/wwwroot/xxx.xxx.com/app/gateway/ws/ssl/server.key',
        'verify_peer' => false,
        // 'allow_self_signed' => true, //如果是自簽名證書需要開啟此選項(xiàng)
    )
);
// websocket協(xié)議(端口任意,只要沒有被其它程序占用就行)
$gateway = new Gateway("websocket://0.0.0.0:8282", $context);
// 開啟SSL,websocket+SSL 即wss
$gateway->transport = 'ssl';

// gateway 進(jìn)程,這里使用Text協(xié)議,可以用telnet測試
//$gateway = new Gateway("text://0.0.0.0:8282");

使用ThinkPHP6的自定義命令開啟服務(wù)

php think make:command Ws 

Ws.php內(nèi)容

<?php
declare (strict_types=1);

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use Workerman\Worker;

class Ws extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('ws')
            ->addArgument('action', Argument::OPTIONAL, "start|stop|restart|reload|status|connections", 'start')
            ->addOption('mode', 'm', Option::VALUE_OPTIONAL, 'Run the workerman server in daemon mode.')
            ->setDescription('workerman');
    }

    protected function execute(Input $input, Output $output)
    {
        $action = $input->getArgument('action');
        $mode = $input->getOption('mode');

        // 重新構(gòu)造命令行參數(shù),以便兼容workerman的命令
        global $argv;

        $argv = [];

        array_unshift($argv, 'think', $action);
        if ($mode == 'd') {
            $argv[] = '-d';
        } else if ($mode == 'g') {
            $argv[] = '-g';
        }
        
        // 檢查擴(kuò)展
        if (!extension_loaded('pcntl')) {
            exit("Please install pcntl extension. See http://doc3.workerman.net/appendices/install-extension.html\n");
        }

        if (!extension_loaded('posix')) {
            exit("Please install posix extension. See http://doc3.workerman.net/appendices/install-extension.html\n");
        }

        // 標(biāo)記是全局啟動(dòng)
        define('GLOBAL_START', 1);

        foreach (glob(app()->getBasePath() . '/gateway/*/start*.php') as $start_file) {
            require_once $start_file;
        }

        Worker::runAll();
    }
}

配置自定義指令,在config/console.php中增加

<?php
// +----------------------------------------------------------------------
// | 控制臺(tái)配置
// +----------------------------------------------------------------------
return [
    // 指令定義
    'commands' => [
        'ws' => \app\command\Ws::class # 增加
    ],
];

命令啟動(dòng)服務(wù)

# debug啟動(dòng)
php think ws start 
# 守護(hù)進(jìn)程啟動(dòng)
php think ws start --mode d
# 停止服務(wù)
php think ws stop

我是docker配置的環(huán)境,報(bào)錯(cuò)了Please install pcntl extension.
因?yàn)?code>pcntl是php自帶的擴(kuò)展,所以只要執(zhí)行命令安裝一下就可以

docker-php-ext-install pcntl  

如果沒有執(zhí)行composer dumpautoload運(yùn)行時(shí)可能會(huì)報(bào)錯(cuò):Waring: Events::onMessage is not callable文章來源地址http://www.zghlxwxcb.cn/news/detail-836073.html

到了這里,關(guān)于ThinkPHP6中使用GatewayWorker的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • thinkphp6 入門教程合集(更新中) thinkphp6 入門(1)--安裝、路由規(guī)則、多應(yīng)用模式

    thinkphp6 入門(1)--安裝、路由規(guī)則、多應(yīng)用模式_軟件工程小施同學(xué)的博客-CSDN博客 thinkphp6 入門(2)--視圖、渲染html頁面、賦值_軟件工程小施同學(xué)的博客-CSDN博客 thinkphp6 入門(3)--獲取GET、POST請(qǐng)求的參數(shù)值_thinkphp獲取get傳值_軟件工程小施同學(xué)的博客-CSDN博客 thinkphp6 入門(

    2024年02月09日
    瀏覽(52)
  • thinkphp6和thinkphp5有什么區(qū)別

    Thinkphp6.0完全開發(fā)手冊(cè) 采用PHP7強(qiáng)類型(嚴(yán)格模式) tp5 環(huán)境要求PHP = 5.4.0 ThinkPHP6.0的環(huán)境要求 PHP = 7.2.5 6.0版本開始,必須通過Composer方式安裝和更新,所以你無法通過Git下載安裝。 支持更多的PSR規(guī)范 V6.0.10版本開始 支持 psr7 response 多應(yīng)用支持 tp5默認(rèn)使用多應(yīng)用模式部署 tp6 安

    2024年02月06日
    瀏覽(21)
  • thinkPHP6接入workman

    thinkPHP6接入workman

    上篇介紹了workman實(shí)現(xiàn)websocket功能(鏈接:https://blog.csdn.net/weixin_38155824/article/details/128952037) 后傳:解決workman部署到Linux環(huán)境無法啟動(dòng)和連接的問題(https://blog.csdn.net/weixin_38155824/article/details/129004050) 這篇就介紹如何在thinkPHP6項(xiàng)目中接入workman。 查看TP6手冊(cè):命令行=自定義命

    2024年02月15日
    瀏覽(34)
  • thinkphp6-配置設(shè)置與獲取,Thinkphp6自定義配置文件以及調(diào)用(config文件夾下的配置)

    thinkphp6-配置設(shè)置與獲取,Thinkphp6自定義配置文件以及調(diào)用(config文件夾下的配置)

    環(huán)境變量 設(shè)置環(huán)境變量 /.env [DATABASE] USERNAME = root PASSWORD = 123456 獲取環(huán)境變量 app/controller/Index.php 訪問測試 http://codeit.org.cn/index {“username”:“root”,“password”:“123456”} 1.在thinkphpconfig下新建一個(gè)test.php配置文件 .test.php文件內(nèi)容 調(diào)用test.php配置文件 配置 配置設(shè)置 config/app.

    2024年02月13日
    瀏覽(34)
  • Thinkphp6 如何 生成二維碼

    來自:https://www.is5.me/notes/php/633.html

    2024年02月11日
    瀏覽(19)
  • thinkphp6 動(dòng)態(tài)開啟debug模式

    1、找到config/app.php?? 2、自定義開啟debug參數(shù)名稱:示例參數(shù)為debug,可以根據(jù)自己項(xiàng)目情況自定義? 3、必須同時(shí)設(shè)置App::debug 和 Env::set(\\\'APP_DEBUG\\\')

    2024年02月07日
    瀏覽(21)
  • ThinkPHP6.0 鏈?zhǔn)絊QL語句

    查詢單個(gè)數(shù)據(jù) 查詢結(jié)果集(查詢結(jié)果返回多條數(shù)據(jù)的意思) ? 查詢一個(gè)字段 ? 查詢一列 添加數(shù)據(jù) 修改數(shù)據(jù) 刪除數(shù)據(jù) 根據(jù)主鍵刪除 ? 條件刪除 ? 查詢數(shù)據(jù) 格式 where(\\\'字段名\\\',\\\'查詢表達(dá)式\\\',\\\'查詢條件\\\'); 模糊查詢 區(qū)間查詢 IN查詢 Not Null Null 鏈?zhǔn)讲僮魇纠?field操作(輸出選擇

    2024年02月11日
    瀏覽(29)
  • ThinkPHP6企業(yè)OA辦公系統(tǒng)

    ThinkPHP6企業(yè)OA辦公系統(tǒng)

    有需要請(qǐng)加文章底部Q哦 可遠(yuǎn)程調(diào)試 ThinkPHP6企業(yè)OA辦公系統(tǒng) 勾股OA基于ThinkPHP6開發(fā),前端Layui,數(shù)據(jù)庫mysql,是一款實(shí)用的企業(yè)辦公系統(tǒng)??啥嘟巧卿?,集成了系統(tǒng)設(shè)置、人事管理、消息管理、審批管理、日常辦公、客戶管理、合同管理、項(xiàng)目管理、財(cái)務(wù)管理等模塊。系統(tǒng)簡

    2024年02月13日
    瀏覽(26)
  • thinkphp6入門(23)-- 如何導(dǎo)入excel

    thinkphp6入門(23)-- 如何導(dǎo)入excel

    1. 安裝phpexcel 2. 前端 3.?后端 注:現(xiàn)在主要使用phpoffice/phpspreadsheet庫,phpoffice/phpexcel已經(jīng)不再維護(hù),但本文由于環(huán)境無法更新,所以就安裝了phpoffice/phpexcel?;静僮饕粯?。 參考:https://www.tpxhm.com/fdetail/725.html 注: 一、在ubuntu環(huán)境下提示?Class \\\'ZipArchive\\\' not found ?查看對(duì)應(yīng)的

    2024年04月14日
    瀏覽(24)
  • ThinkPHP6之?dāng)?shù)據(jù)庫操作上

    ThinkPHP6之?dāng)?shù)據(jù)庫操作上

    注意,tp6在進(jìn)行語法學(xué)習(xí)的時(shí)候都是在app/index.php中寫代碼的,代碼寫在index函數(shù)下面,而且 tp6自帶的文件都是由自動(dòng)加載器的,不需要包含autoload.php文件 要對(duì)數(shù)據(jù)庫進(jìn)行操作,要修改兩個(gè)地方,一個(gè)數(shù).env文件,一個(gè)是config/database.php文件 config/database.php connections里面的一個(gè)子

    2024年02月01日
    瀏覽(16)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包