think-swoole 3.0入门教程(thinkphp 6.0)

栏目: PHP · 发布时间: 7年前

内容简介:ThinkPHP即将迎来最新版本6.0,针对目前越来越流行Swoole,thinkphp也推出了最新的扩展think-swoole 3.0由于目前thinkphp 6.0没有稳定版本,所以只能安装开发板接下来安装think-swoole 3.0,目前最新的稳定版本是3.0.2

前言

ThinkPHP即将迎来最新版本6.0,针对目前越来越流行Swoole,thinkphp也推出了最新的扩展think-swoole 3.0

安装

由于目前thinkphp 6.0没有稳定版本,所以只能安装开发板

composer create-project topthink/think tp 6.0.*-dev

接下来安装think-swoole 3.0,目前最新的稳定版本是3.0.2

composer require topthink/think-swoole

配置

安装结束可以根据自己的需求对配置信息进行修改。TP6的配置信息都存在于外部的config目录,这里主要介绍swoole相关配置信息

use think\swoole\websocket\room\TableRoom;
use think\swoole\websocket\socketio\Handler;
use think\swoole\websocket\socketio\Parser;

return [
    'server'           => [
        'host'      => '0.0.0.0', // 监听地址
        'port'      => 80, // 监听端口
        'mode'      => SWOOLE_PROCESS, // 运行模式 默认为SWOOLE_PROCESS
        'sock_type' => SWOOLE_SOCK_TCP, // sock type 默认为SWOOLE_SOCK_TCP
        'options'   => [
            'pid_file'              => runtime_path() . 'swoole.pid',//主进程ID保存文件路径
            'log_file'              => runtime_path() . 'swoole.log',//swoole日志文件
            'daemonize'             => false,
            // Normally this value should be 1~4 times larger according to your cpu cores.
            'reactor_num'           => swoole_cpu_num(),//线程数,默认值即可,不设置也可以
            'worker_num'            => swoole_cpu_num(),//worker进程数量
            'task_worker_num'       => swoole_cpu_num(),//异步任务进程数量
            'enable_static_handler' => true,//是否启用静态服务,如果开启,则优先判断指定的web目录下是否存在请求的静态文件,如果存在,则直接返回
            'document_root'         => root_path('public'),//web目录
            'package_max_length'    => 20 * 1024 * 1024,
            'buffer_output_size'    => 10 * 1024 * 1024,
            'socket_buffer_size'    => 128 * 1024 * 1024,
            'max_request'           => 3000,
            'send_yield'            => true,
        ],
    ],
    'websocket'        => [
        'enabled'       => false,//是否开启
        'handler'       => Handler::class,//处理请求的类,可以自定义
        'parser'        => Parser::class,//处理解析的类,可以自定义
        'route_file'    => base_path() . 'websocket.php',//websocket路由文件
        'ping_interval' => 25000,
        'ping_timeout'  => 60000,
        'room'          => [
            'type'        => TableRoom::class,
            'room_rows'   => 4096,
            'room_size'   => 2048,
            'client_rows' => 8192,
            'client_size' => 2048,
        ],
    ],
    'auto_reload'      => false,
    'enable_coroutine' => true,
    'resetters'        => [],
    'tables'           => [],
];

启动

php think swoole

执行上述命令则可以启动web服务

如果需要使用守护进程方式运行,可以配置

'options'   =>  [
    'daemonize' =>  true
]

支持的命令

php think swoole [start|stop|reload|restart]

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Dynamic Programming

Dynamic Programming

Richard Bellman / Dover Publications / 2003-03-04 / USD 19.95

An introduction to the mathematical theory of multistage decision processes, this text takes a "functional equation" approach to the discovery of optimum policies. The text examines existence and uniq......一起来看看 《Dynamic Programming》 这本书的介绍吧!

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具