日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網(wǎng)站首頁 編程語言 正文

tp6 集成swoole

作者:一直向錢 更新時間: 2022-05-12 編程語言

swoole不能在windows運行,我們在linux系統(tǒng)上部署項目運行,在使用前必須安裝好swoole

linux安裝好swoole后,就可以在tp6框架下載集成 swoole模塊,如下:

使用 composer 安裝 think-swoole 擴展。即執(zhí)行 composer require topthink/think-swoole

然后在config目錄下自動生成一個swoole.php的配制文件,修改配制文件內容如下

修改監(jiān)聽IP和端口號、options 里的daemonize改成true,默認為false,之前沒有修改報很多錯誤,無法運行起來,pool連接池enable改為true

 [
        'host'      => env('SWOOLE_HOST', '0.0.0.0'), // 監(jiān)聽地址
        'port'      => env('SWOOLE_PORT', 8090), // 監(jiān)聽端口
        'mode'      => SWOOLE_PROCESS, // 運行模式 默認為SWOOLE_PROCESS
        'sock_type' => SWOOLE_SOCK_TCP, // sock type 默認為SWOOLE_SOCK_TCP
        'options'   => [
            'pid_file'              => runtime_path() . 'swoole.pid',
            'log_file'              => runtime_path() . 'swoole.log',
            'daemonize'             => true,
            // Normally this value should be 1~4 times larger according to your cpu cores.
            'reactor_num'           => swoole_cpu_num(),
            'worker_num'            => swoole_cpu_num(),
            'task_worker_num'       => swoole_cpu_num(),
            'enable_static_handler' => true,
            'document_root'         => root_path('public'),
            'package_max_length'    => 20 * 1024 * 1024,
            'buffer_output_size'    => 10 * 1024 * 1024,
            'socket_buffer_size'    => 128 * 1024 * 1024,
        ],
    ],
    'websocket'  => [
        'enable'        => false,
        'handler'       => Handler::class,
        'ping_interval' => 25000,
        'ping_timeout'  => 60000,
        'room'          => [
            'type'  => 'table',
            'table' => [
                'room_rows'   => 4096,
                'room_size'   => 2048,
                'client_rows' => 8192,
                'client_size' => 2048,
            ],
            'redis' => [
                'host'          => '127.0.0.1',
                'port'          => 6379,
                'max_active'    => 3,
                'max_wait_time' => 5,
            ],
        ],
        'listen'        => [],
        'subscribe'     => [],
    ],
    'rpc'        => [
        'server' => [
            'enable'   => false,
            'port'     => 9000,
            'services' => [
            ],
        ],
        'client' => [
        ],
    ],
    'hot_update' => [
        'enable'  => env('APP_DEBUG', true),
        'name'    => ['*.php'],
        'include' => [app_path()],
        'exclude' => [],
    ],
    //連接池
    'pool'       => [
        'db'    => [
            'enable'        => true,
            'max_active'    => 3,
            'max_wait_time' => 5,
        ],
        'cache' => [
            'enable'        => true,
            'max_active'    => 3,
            'max_wait_time' => 5,
        ],
        //自定義連接池
    ],
    //隊列
    'queue'      => [
        'enable'  => false,
        'workers' => [],
    ],
    'coroutine'  => [
        'enable' => true,
        'flags'  => SWOOLE_HOOK_ALL,
    ],
    'tables'     => [],
    //每個worker里需要預加載以共用的實例
    'concretes'  => [],
    //重置器
    'resetters'  => [],
    //每次請求前需要清空的實例
    'instances'  => [],
    //每次請求前需要重新執(zhí)行的服務
    'services'   => [],
];

?可以在根目錄下執(zhí)行命令? php think swoole start? 進行啟動程序,如圖下

php 安裝 fileinfo 擴展,需要解除禁用的函數(shù):putenv,proc_open

?

原文鏈接:https://blog.csdn.net/u013519290/article/details/124592745

欄目分類
最近更新