• Stars
    star
    444
  • Rank 94,913 (Top 2 %)
  • Language
    PHP
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Swoole extend for thinkphp

ThinkPHP Swoole 扩展

交流群:787100169 点击加群

安装

首先按照Swoole官网说明安装swoole扩展,然后使用

composer require topthink/think-swoole

安装swoole扩展。

使用方法

直接在命令行下启动HTTP服务端。

php think swoole

启动完成后,默认会在0.0.0.0:8080启动一个HTTP Server,可以直接访问当前的应用。

swoole的相关参数可以在config/swoole.php里面配置(具体参考配置文件内容)。

如果需要使用守护进程方式运行,建议使用supervisor来管理进程

访问静态文件

4.0开始协程风格服务端默认不支持静态文件访问,建议使用nginx来支持静态文件访问,也可使用路由输出文件内容,下面是示例,可参照修改

  1. 添加静态文件路由:
Route::get('static/:path', function (string $path) {
    $filename = public_path() . $path;
    return new \think\swoole\response\File($filename);
})->pattern(['path' => '.*\.\w+$']);
  1. 访问路由 http://localhost/static/文件路径

队列支持

4.0开始协程风格服务端没有task进程了,使用think-queue代替

使用方法见 think-queue

以下配置代替think-queue里的最后一步:监听任务并执行,无需另外起进程执行队列

return [
    // ...
    'queue'      => [
        'enable'  => true,
        //键名是队列名称
        'workers' => [
            //下面参数是不设置时的默认配置
            'default'            => [
                'delay'      => 0,
                'sleep'      => 3,
                'tries'      => 0,
                'timeout'    => 60,
                'worker_num' => 1,
            ],
            //使用@符号后面可指定队列使用驱动
            'default@connection' => [
                //此处可不设置任何参数,使用上面的默认配置
            ],
        ],
    ],
    // ...
];

支持symfony/var-dumper

由于应用是通过php cli启动的,所以默认symfony/var-dumper会将调试信息打印在控制台, 通过配置中间件来支持将调试信息输出在网页上 如下是直接在配置在全局中间件上,也可以在路由定义的时候配置

// app/middleware.php

<?php
// 全局中间件定义文件
return [
    // 全局请求缓存
    // \think\middleware\CheckRequestCache::class,
    // 多语言加载
    // \think\middleware\LoadLangPack::class,
    // Session初始化
    //\think\middleware\SessionInit::class,
    \think\swoole\middleware\InteractsWithVarDumper::class,
];

More Repositories

1

think

ThinkPHP Framework ——十年匠心的高性能PHP框架
PHP
7,795
star
2

thinkphp

ThinkPHP3.2 ——基于PHP5的简单快速的面向对象的PHP框架
PHP
2,879
star
3

framework

ThinkPHP Framework
PHP
2,671
star
4

think-queue

ThinkPHP 队列支持
PHP
555
star
5

think-orm

Think ORM——the PHP Database&ORM Framework
PHP
385
star
6

think-awesome

awesome for thinkphp
242
star
7

think-worker

Workerman extend for ThinkPHP
PHP
184
star
8

think-throttle

thinkphp 限制访问频率的中间件
PHP
176
star
9

think-captcha

thinkphp 验证码类库
PHP
112
star
10

think-mongo

mongodb driver for thinkphp
PHP
101
star
11

think-migration

thinkphp 数据库迁移工具
PHP
89
star
12

think-helper

thinkphp常用的助手类 助手函数
PHP
78
star
13

thinkphp-extend

PHP
73
star
14

think-image

thinkphp5 图像处理类
PHP
59
star
15

think-validate

think Validate
PHP
51
star
16

think-template

the php template engine
PHP
49
star
17

think-annotation

ThinkPHP6注解
PHP
43
star
18

think-angular

think-angular模板引擎
PHP
40
star
19

think-testing

ThinkPHP 5 应用单元测试组件
PHP
40
star
20

think-oracle

Oracle数据库驱动
PHP
36
star
21

think-cache

PHP Cache Service
PHP
31
star
22

think-ide-helper

PHP
24
star
23

think-api

官方API服务SDK
PHP
22
star
24

think-multi-app

thinkphp6 multi app support
PHP
21
star
25

think-debugbar

ThinkPHP Debugbar (Integrates PHP Debug Bar)
PHP
17
star
26

think-glide

ThinkPHP adapter for using Glide image manipulation library
PHP
16
star
27

think-seaslog

SeasLog driver for thinkphp
PHP
15
star
28

think-editor

The ThinkPHP5 Editor Package
PHP
15
star
29

think-view

thinkphp driver for think-template
PHP
14
star
30

think-installer

PHP
14
star
31

think-container

PHP Container & Facade Manager
PHP
14
star
32

thinkng-webapp

Thinkng的应用模板
PHP
12
star
33

think-sae

sae support for thinkphp5
PHP
11
star
34

think-workflow

ThinkPHP6状态机
PHP
11
star
35

think-log

PHP
10
star
36

think-trace

debug trace bar for thinkphp6
PHP
9
star
37

think-filesystem

thinkphp 文件系统
PHP
8
star
38

think-tracing

PHP
8
star
39

think-one

一个tp5的辅助开发插件
HTML
7
star
40

think-csrf

thinkphp5 CSRF 保护组件
5
star
41

think-yaconf

PHP
4
star
42

think-socketlog

socketlog driver for thinkphp
PHP
4
star
43

cache-bridge

PSR-16 to PSR-6 Bridge
PHP
3
star
44

think-factory

thinkphp 工厂类
PHP
2
star