├── .gitignore ├── LICENSE.md ├── README.md ├── en └── documentation.md ├── zh-Hans ├── attentions.md ├── configuration.md ├── contributions.md ├── documentation.md ├── donation.md ├── guides.md ├── homer.md ├── http.md ├── installation.md ├── releases.md ├── running.md ├── server.md ├── snowflake.md ├── structure.md ├── upgrade.md └── websocket.md └── zh-Hant └── documentation.md /.gitignore: -------------------------------------------------------------------------------- 1 | # OS and Editor files 2 | ._* 3 | .DS_Store 4 | Thumbs.db 5 | .idea 6 | .project 7 | .settings 8 | .tmproj 9 | *.sublime-project 10 | *.sublime-workspace 11 | nbproject 12 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) You Ming 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lawoole Documentation 2 | 3 | Lawoole is a high-performance PHP framework based on Laravel and Swoole. 4 | 5 | ## Select your language 6 | 7 | - [简体中文](zh-Hans/documentation.md) 8 | - [繁體中文](zh-Hant/documentation.md) 9 | - [English](en/documentation.md) 10 | 11 | ## About Lawoole 12 | 13 | Laravel is the most popular PHP framework. 14 | It is dedicated to helping developers write the most elegant and meaningful code, 15 | and also provides a wealth of functions to developers through the ecological chain. 16 | 17 | As we all know, Laravel's biggest flaw is the performance problems behind its rich features. 18 | Lawoole was born to solve this problem. 19 | By using Swoole as an infrastructure, it not only enhances the efficiency of network communication, 20 | but also avoids the consumption of repeated compilation. 21 | At the same time, Lawoole did not sacrifice the outstanding features of Laravel. 22 | In Lawoole, you can have a development experience consistent with Laravel and write creative code. 23 | 24 | Lawoole differs from other Swoole-based frameworks in that it does not focus on performance, 25 | but rather seeks a balance between a comfortable code writing environment and program efficiency. 26 | Lawoole does not admire those who sacrificed code readability and wrote hard-to-maintain and error-prone code. 27 | 28 | Thank for the shoulders of giants: 29 | 30 | - Laravel ( [https://laravel.com](https://laravel.com) ) 31 | - Swoole ( [https://www.swoole.com](https://www.swoole.com) ) 32 | 33 | ## Community 34 | 35 | - QQ Group: 729916224 36 | 37 | ## Contribution Guidelines 38 | 39 | We are very honored to welcome your contribution to the Laravel manual. 40 | 41 | If you are submitting documentation for the current stable release, submit it to the corresponding branch. 42 | For example, documentation for Lawoole 1.0 would be submitted to the `1.0` branch. 43 | Documentation intended for the next release of Lawoole should be submitted to the master branch. -------------------------------------------------------------------------------- /en/documentation.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lawoole/docs/ae4e58033143f87ade009758b203b6141075f501/en/documentation.md -------------------------------------------------------------------------------- /zh-Hans/attentions.md: -------------------------------------------------------------------------------- 1 | # 注意事项 -------------------------------------------------------------------------------- /zh-Hans/configuration.md: -------------------------------------------------------------------------------- 1 | # 配置 2 | 3 | - [介绍](#introduction) 4 | - [环境配置](#environment-configuration) 5 | - [环境配置类型](#environment-variable-types) 6 | - [配置覆盖规则](#override-rules) 7 | 8 | 9 | ## 介绍 10 | 11 | 与 Laravel 相同,在 Lawoole 中,配置文件被存放在 `config` 这个文件夹中,而且格式也是相同的。也就是说,你可以毫不费劲的从 Laravel 项目中迁移你的配置到 Lawoole 项目里,不需要做任何改动。 12 | 13 | 14 | ## 环境配置 15 | 16 | 因为与环境有关的配置可以放置在项目之外的独立文件中,所以基于 Laravel 的程序能够很容易的运行在不同的环境中。 17 | 18 | 在 Laravel 中,通过 Vance Lucas 的 [DotEnv](https://github.com/vlucas/phpdotenv) 工具库,我们可以在 `.env` 文件里配置这些环境配置,并通过 `env()` 函数引入它们。这是一个很好的方案,但却也蕴藏着很多限。在 Lawoole 中,`.env` 中的配置不会再被读取,取而代之的独立的环境配置文件。 19 | 20 | 所有环境配置,都存放在 `config` 文件夹下的 `environment` 的文件夹中。环境配置文件的命名,与 `config` 中配置文件的命名是一致且一一对应的。 21 | 22 | 举个例子,如果你想要修改 `cache.php` 配置中的 `default` 这一配置以达到使用不同的默认缓存驱动的目的,那么你可以在 `config/environment` 创建一个同名的 `cache.php` 环境配置文件。 23 | 24 | ```php 25 | return [ 26 | 27 | 'default' => 'redis', 28 | 29 | // ... 30 | 31 | ]; 32 | ``` 33 | 34 | 35 | ### 环境配置类型 36 | 37 | 得益于 Lawoole 中的环境配置采用了 PHP 语法,所以其支持的变量类型比 `.env` 结构的定义方式丰富很多,我们可以通过下表进行比较。 38 | 39 | 数据类型 | Laravel | Lawoole 40 | :---- | :---- | :---- 41 | string | 支持 | 支持 42 | integer | | 支持 43 | float | | 支持 44 | boolean | 支持 | 支持 45 | null | 支持 | 支持 46 | array | | 支持 47 | object | | 支持 48 | 49 | 50 | ### 配置覆盖规则 51 | 52 | 与 Laravel 相比,在 Lawoole 中使用环境配置替换默认配置,你将得到更多的灵活性。 53 | 54 | 在 Lawoole 的环境配置文件中,支持 `.` 深层替换方法,也就是说,你可以选择覆盖原有配置中任何一个层级的内容。 55 | 下面这个示例可以帮助你更好的理解这种配置覆盖方法。 56 | 57 | ```php 58 | return [ 59 | 60 | // 仅更改 MySQL 的 host 配置 61 | 62 | 'connections.mysql.host' => '...', 63 | 64 | // 覆盖全部 SQLite 的配置 65 | 66 | 'connections.sqlite' => [ 67 | 'driver' => 'sqlite', 68 | 'database' => storage_path('database/lawoole.sqlite'), 69 | ], 70 | 71 | // 更新全部链接中的 password 配置 72 | 73 | 'connections' => function ($connections) { 74 | return array_map(function ($connection) { 75 | $connection['password'] = '...'; 76 | 77 | return $connection; 78 | }, $connections); 79 | } 80 | 81 | ]; 82 | ``` 83 | 84 | > {tip} 虽然 `.env` 文件不会被读取,但并不意味着 `env()` 函数是无效的,你仍然可以通过它获得来自控制台或者系统的环境配置。 85 | 86 | -------------------------------------------------------------------------------- /zh-Hans/contributions.md: -------------------------------------------------------------------------------- 1 | # 贡献代码 2 | 3 | 4 | -------------------------------------------------------------------------------- /zh-Hans/documentation.md: -------------------------------------------------------------------------------- 1 | - ## 序言 2 | - [指南](guides.md) 3 | - [版本更新记录](releases.md) 4 | - [升级与迁移](upgrade.md) 5 | - [贡献代码](contributions.md) 6 | 7 | - ## 起步 8 | - [安装](installation.md) 9 | - [配置](configuration.md) 10 | - [目录结构](structure.md) 11 | - [运行](running.md) 12 | 13 | - ## 基础 14 | - [Server](server.md) 15 | - [Http](http.md) 16 | - [Homer](homer.md) 17 | - [WebSocket](websocket.md) 18 | - [Snowflake](snowflake.md) 19 | 20 | - ## 深入 21 | - [注意事项](attentions.md) 22 | 23 | - ## 附录 24 | - [捐助](donation.md) -------------------------------------------------------------------------------- /zh-Hans/donation.md: -------------------------------------------------------------------------------- 1 | # 捐助 -------------------------------------------------------------------------------- /zh-Hans/guides.md: -------------------------------------------------------------------------------- 1 | # 指南 2 | 3 | - [关于 Lawoole](#about-lawoole) 4 | 5 | 6 | ## 关于 Lawoole 7 | 8 | Lawoole 是基于 Laravel 和 Swoole 的高性能 PHP 框架。 9 | 10 | Laravel 是目前热度最高的 PHP 框架,其在致力于帮助开发者书写最优雅、达意代码的同时,也通过生态链向广大开发者提供了丰富的功能。 11 | 12 | 众所周知,Laravel 最大的缺陷莫过于其丰富功能背后带来的性能问题,Lawoole 正是为了解决这一问题而生。 13 | 通过以 Swoole 为基础设施,不但强化了网络通讯的效率,也避免了重复编译带来的消耗。 14 | 与此同时,Lawoole 并没有牺牲 Laravel 中优秀的特性,在 Lawoole 中,你可以拥有与 Laravel 一致的开发体验,编写那些富有创造力的代码。 15 | 16 | Lawoole 与其他基于 Swoole 的框架所有不同,其并不过分追求性能,而是在舒适的代码编写环境与程序运行效率之间寻找平衡。 17 | Lawoole 并不推崇那些过分最求性能而牺牲代码可读性,编写难以维护并容易出错代码的行为。 18 | 19 | 由衷感谢巨人的肩膀: 20 | 21 | - Laravel ( [https://laravel.com](https://laravel.com) ) 22 | - Swoole ( [https://www.swoole.com](https://www.swoole.com) ) -------------------------------------------------------------------------------- /zh-Hans/homer.md: -------------------------------------------------------------------------------- 1 | # Homer 2 | 3 | - [介绍](#introduction) 4 | - [基础使用](#basic-usage) 5 | - [定义接口](#define-interface) 6 | - [中间件](#middleware) 7 | 8 | 9 | ## 介绍 10 | 11 | Homer 是 Lawoole 中的重量级模块,其提供了非常方便的 RPC 功能。 12 | 13 | 与其他 PHP RPC 框架不同,通过 Homer 实现远程调用是无感知的,你甚至可以在不修改现有代码的前提下,实现本地调用到远程调用的切换。 14 | 15 | 16 | ## 基础使用 17 | 18 | 使用 Homer 前,需要把 `Lawoole\Homer\HomerServiceProvider` 引入到 `app.providers` 这个配置项中。 19 | 20 | 如果你是以服务方来运行,以期望 Homer 向外提供服务时,还需要在 `server.listens` 里添加服务监听。Lawoole Homer 支持多种传输协议,只需要在 `server.listens` 指定它们以及关联的事件处理器即可。 21 | 22 | - **whisper** Lawoole\Homer\Transport\Whisper\WhisperServerSocketHandler 23 | - **http** Lawoole\Homer\Transport\Http\HttpServerSocketHandler 24 | 25 | 如果你作为客户端,希望连接到指定的服务器,则可以通过 `homer.php` 中的 `clients` 这个配置来定义服务器的参数。这里是一个简单的例子,我们通过 `url` 指定了远程的连接地址(包括协议、主机、端口),另外还有超时时间和连接丢失重试次数等。 26 | 27 | ```php 28 | 'clients' => [ 29 | 30 | 'remote' => [ 31 | 'url' => 'whisper://127.0.0.1:8081', 32 | 'timeout' => 5000, 33 | 'retry_times' => 1, 34 | ], 35 | 36 | ], 37 | ``` 38 | 39 | 40 | ## 定义接口 41 | 42 | 在开发前先定义接口是非常好的习惯,而在 Homer 中,服务器与客户端调用就是通过接口来约定的。服务端定义的接口可以拷贝到客户端中,但我们更期望大家能够通过 composer 来管理接口以及它们的更新。 43 | 44 | ```php 45 | interface EchoServiceInterface 46 | { 47 | /** 48 | * Ping the server and get pong. 49 | * 50 | * @return \DateTime 51 | */ 52 | public function ping(); 53 | } 54 | ``` 55 | 56 | 对于定义好的接口,我们可以通过 `homer.php` 来申明,以便 Homer 识别和使用它们。 57 | 58 | 在服务端,我们需要通过 `homer.services` 来指定接口和它们的实现。通过这个绑定,当客户端调用这个接口时,Homer 会自动采用对应的实现类来处理调用并返回结果。 59 | 60 | ```php 61 | 'services' => [ 62 | [ 63 | 'interface' => App\Services\EchoServiceInterface::class, 64 | 'refer' => App\Services\EchoService::class, 65 | ], 66 | ], 67 | ``` 68 | 69 | 在客户端,我们则通过 `homer.references` 来引用远程服务。在这个配置里,我们可以指定接口以及远程服务的配置名,具体的远程服务会采用 `homer.clients` 中的定义。 70 | 71 | ```php 72 | 'references' => [ 73 | [ 74 | 'interface' => App\Services\EchoServiceInterface::class, 75 | 'client' => 'remote', 76 | ], 77 | ], 78 | ``` 79 | 80 | 在客户端中定义的接口,会在 Lawoole 启动后注册到容器中,所以我们可以忽略与它们相关的所有内部实现,直接通过容器来调用它们。 81 | 82 | ```php 83 | $pong = app(EchoServiceInterface::class)->ping(); 84 | ``` 85 | 86 | 上面这段代码看上去与我们通常编写的本地调用代码并无差别,但其实它已经通过 Homer 形成了对远程服务的调用。 87 | 88 | 89 | ## 中间件 90 | 91 | 在 Homer 里,也存在于 Http 服务相类似的中间件机制,而且我们能够在客户端和服务端分别设置和使用。通过中间件,我们可以完成服务熔断、调用统计等功能。 92 | 93 | 中间件的定义可以通过 `homer.middleware`、`homer.name_middleware` 和 `homer.middleware_groups` 来完成,它们的含义与 Http 的中间件相类似。 94 | -------------------------------------------------------------------------------- /zh-Hans/http.md: -------------------------------------------------------------------------------- 1 | # Http 2 | 3 | - [使用 Http 服务](#use-http-server) 4 | - [定义路由](#define-router) 5 | - [中间件](#middleware) 6 | 7 | 8 | ## 使用 Http 服务 9 | 10 | 如果需要开启应用对 Http 请求处理的支持,可以在配置项 `app.providers` 中增加 `Lawoole\Http\HttpServiceProvider`,这会让与 Http 相关的路由机制等被载入到 Lawoole 中。 11 | 12 | 接下来,我们需要在 `server.listens` 的监听中,增加对 Http 协议的监听,在此监听中,请使用 `Lawoole\Http\HttpServerSocketHandler` 作为监听处理器。 13 | 14 | 15 | ## 定义路由 16 | 17 | 与 Laravel 一致,在 Lawoole 中对 Http 路由的定义是完全一致的,路由文件我们可以存放于 routes 这个目录中。 18 | 19 | 除了定义路由文件外,我们还需要做的是对路由入口的配置。在 Laravel 中,我们需要通过继承 RouteServiceProvider 来实现这个功能,而在 Lawoole 中,我们只需要通过 `http.php` 这个配置文件就可以实现。 20 | 21 | 通过 `http.namespace` 这个配置项,我们能够设置全局的控制器命名空间前缀。 22 | 23 | 在 `http.routes` 里,我们能够引入路由规则文件。这个配置项是一个数组,我们可以简单的将文件通过 `route_path('web.php')` 的形式直接放置在其中,实现对路由定义的引入。 24 | 25 | 26 | ## 中间件 27 | 28 | 在 Laravel 中,定义中间件需要继承 Http Kernel 来完成,这显然太过繁琐。在 Lawoole 简化了这个过程,我们依然能够通过 `http.php` 这个配置文件来完成对中间件的配置。 29 | 30 | 在 `http.php` 中,我们可以通过 `middleware`、`route_middleware` 和 `middleware_groups` 来定义中间件,其定义形式与 Laravel 中在 Http Kernel 里定义中间件的方式是一致的。 31 | -------------------------------------------------------------------------------- /zh-Hans/installation.md: -------------------------------------------------------------------------------- 1 | # 安装 2 | 3 | - [安装](#installation) 4 | - [运行环境要求](#basic-requirements) 5 | - [安装 Lawoole](#installing-lawoole) 6 | 7 | 8 | ## 安装 9 | 10 | 11 | ### 运行环境要求 12 | 13 | 在安装和运行 Lawoole 应用前,请确保应用的运行环境符合下面的要求: 14 | 15 | - PHP >= 7.1.3 16 | - Swoole PHP 扩展 >= 1.10.5 17 | - OpenSSL PHP 扩展 18 | - PDO PHP 扩展 19 | - Mbstring PHP 扩展 20 | - Tokenizer PHP 扩展 21 | - XML PHP 扩展 22 | - Ctype PHP 扩展 23 | - JSON PHP 扩展 24 | - BCMath PHP 扩展 25 | 26 | 27 | ### 安装 Lawoole 28 | 29 | 与 Laravel 一致,Lawoole 也是通过 [Composer](https://getcomposer.org) 来管理依赖关系。 30 | 所以说,在使用 Lawoole 前,请确保运行环境中装有 Composer。 31 | 32 | #### 通过 Composer 创建项目 33 | 34 | 通过 Composer 提供的 `create-project` 命令,可以非常轻松的创建一个标准的 Lawoole 项目: 35 | 36 | composer create-project --prefer-dist lawoole/lawoole project-name 37 | -------------------------------------------------------------------------------- /zh-Hans/releases.md: -------------------------------------------------------------------------------- 1 | # 版本更新记录 2 | 3 | - [版本定义](#versioning-scheme) 4 | - [依赖](#dependencies) 5 | - [Lawoole 1.0](#lawoole-1.0) 6 | 7 | 8 | ## 版本定义 9 | 10 | Lawoole 框架定义版本号的方式与 Laravel 近似,采用 `paradigm.major.minor` 这种形式。 11 | 12 | 13 | ## 依赖 14 | 15 | Lawoole 是基于 Laravel 框架以及 Swoole 扩展的,在不同版本的 Lawoole 中,对这两者的依赖也有一定的区别。 16 | 17 | **Lawoole 版本** | **发布时间** | **基于 Laravel 版本** | **最低 Swoole 版本** 18 | :---|:---|:---|:---| 19 | 0.5 | 2018-06-20 | 5.6 | 1.10.5 20 | 1.0 | 2019-01-01 | 5.7 | 1.10.5 21 | 22 | > {notice} 由于 Laravel 的大部分逻辑设计与 Swoole 协程不相兼容,故 Lawoole 不针对协程模式做任何适配,强烈建议在使用 Lawoole 时关闭 Swoole 协程模式,除非你能很好的处理所有的副作用。 23 | 24 | 25 | ## Lawoole 1.0 26 | 27 | -------------------------------------------------------------------------------- /zh-Hans/running.md: -------------------------------------------------------------------------------- 1 | # 运行 2 | 3 | - [控制台](#console) 4 | 5 | 6 | ## 控制台 7 | 8 | 启动 Lawoole 项目需要通过控制台完成,操作命令通过项目中的 `artisan` 和 `server` 两个脚本传入。 9 | 10 | 可以通过 `artisan` 来启动服务: 11 | 12 | ```shell 13 | php artisan server:start 14 | ``` 15 | 16 | 而上面的命令也可以简化通过 `server` 脚本来完成: 17 | 18 | ```shell 19 | php server 20 | ``` 21 | -------------------------------------------------------------------------------- /zh-Hans/server.md: -------------------------------------------------------------------------------- 1 | # Server 2 | 3 | - [介绍](#introduction) 4 | - [配置服务](#configure-server) 5 | 6 | 7 | ## 介绍 8 | 9 | Server 是 Lawoole 提供网络服务的模块,其核心就是 Swoole 的 Server。 10 | 11 | 当我们通过 `php artisan server:start` 启动 Lawoole 项目时,其实启动的就是以 Server 为基础的一个服务。令人愉悦的是,Lawoole 对 Swoole Server 进行了非常友好的封装,可以让大家在极其愉悦的编程体验中使用到它们。 12 | 13 | 14 | ## 配置服务 15 | 16 | 对于 Server 相关的配置是通过 `config` 目录下的 `server.php` 这个配置文件来完成的。 17 | 18 | 在这个文件中,我们可以配置: 19 | 20 | ### 服务驱动类型 21 | 22 | 通过 `server.driver` 来指定 Server 的基础驱动,目前支持的驱动有: 23 | 24 | - **tcp** 能够支持 TCP 协议连接 25 | - **http** 能够支持 TCP 协议和 Http 协议连接 26 | - **websocket** 能够支持 TCP、Http 和 WebSocket 协议连接 27 | 28 | ### 服务器选项 29 | 30 | 通过 `server.options` 能够对 Server 进行配置,这里的配置项继承于 Swoole 对 Server 的服务选项。 31 | 32 | 常见的配置有: 33 | 34 | - **worker_num** 工作进程数 35 | - **task_worker_num** 任务工作进程数 36 | 37 | 更多完整配置选项,可以参阅 (Swoole Server 配置选项)[https://wiki.swoole.com/wiki/page/274.html] 38 | 39 | ### 端口监听 40 | 41 | 通过 `server.listens` 可以指定 Server 对端口的监听和协议请求的处理。这个配置项是一个数组,我们能够同时设置多个端口监听,并处理不同的协议请求。这些请求的处理,是共享工作进程的。 42 | 43 | 对于每个监听来说,我们需要配置: 44 | 45 | - **protocol** 处理协议 46 | - **host** 监听主机 47 | - **port** 监听端口 48 | - **handler** 事件处理器 49 | 50 | > {tip} 监听主机 `host` 指的是机器的网卡 IP,如果对此不够熟悉,可以使用 0.0.0.0 来监听所有网卡。 51 | 52 | 事件处理器是监听中的关键,我们正是通过它来处理网络事件。不过,如果只是普通用户,你无须关心它们的实现,因为 Lawoole 已经包含了 Http 协议、WebSocket 协议以及 Homer 相关的事件处理器,你只需要直接使用它们即可。 53 | -------------------------------------------------------------------------------- /zh-Hans/snowflake.md: -------------------------------------------------------------------------------- 1 | # Snowflake 2 | 3 | - [介绍](#introduction) 4 | - [基础使用](#basic-usage) 5 | 6 | 7 | ## 介绍 8 | 9 | Snowflake 算法是 Twitter 设计的一个分布式 ID 生成算法,Snowflake 模块基于 Swoole 对 Snowflake 算法进行了优化,实现了分布式 ID 的生成功能。 10 | 11 | Lawoole 的 Snowflake 算法在 Twitter 原始的 Snowflake 算法基础上进行了一定的修改,使其更适应于在 Swoole 环境下生成 ID。 12 | 在 Lawoole 的 Snowflake 算法中,生成 ID 的位信息含义如下: 13 | 14 | 0 - 31 | 32 - 36 | 37 - 41 | 42 - 52 | 53 - 63 15 | :------:|:-------:|:-------:|:-------:|:-------:| 16 | 秒序 | 机器编号 | 随机数 | 进程号 | 自增数 17 | 18 | 19 | ## 基础使用 20 | 21 | 你可以很轻松的使用 `Snowflake` 外观来生成一个新的 Snowflake ID: 22 | 23 | ```php 24 | $id = Snowflake::nextId(); 25 | ``` 26 | 27 | #### 修改机器编码 28 | 29 | 在默认情况下,Snowflake 会基于本地的 MAC 网络地址生成一个机器编码,如果你希望对其进行修改,可以使用 `setMachineId` 方法: 30 | 31 | ```php 32 | Snowflake::setMachineId(6); 33 | ``` 34 | -------------------------------------------------------------------------------- /zh-Hans/structure.md: -------------------------------------------------------------------------------- 1 | # 目录结构 2 | 3 | - [介绍](#introduction) 4 | 5 | 6 | ## 介绍 7 | 8 | 在目录结构上,Lawoole 项目与 Laravel 项目几乎没有区别,所以可以很轻松的将 Laravel 项目迁移成为 Lawoole 项目。 9 | 10 | 关于项目结构的说明,可以直接参阅 Laravel 的文档:[Laravel 5.7 目录结构](https://laravel-china.org/docs/laravel/5.7/structure/2244) 11 | -------------------------------------------------------------------------------- /zh-Hans/upgrade.md: -------------------------------------------------------------------------------- 1 | # 升级与迁移 2 | 3 | - [从 Laravel 迁移项目](#migrate-from-laravel) 4 | 5 | 6 | ## 从 Laravel 迁移项目 7 | 8 | Lawoole 相比较于其他使用 Swoole 提速 Laravel 的项目,最大的优势在于 Lawoole 是基于 Laravel 的完整框架而非一个组件。 9 | 得益于此,Lawoole 能够很轻松的兼容所有 Laravel 及周边的软件或功能包,而不能直接兼容的包,在进行一定针对性的适配后,也能够正常使用。 10 | 所以,你可以很轻松的将项目从 Laravel 迁移至 Lawoole 中。 11 | 如果你之前编写了全面的单元测试,那么检查迁移后程序的运行情况将会非常方便。 -------------------------------------------------------------------------------- /zh-Hans/websocket.md: -------------------------------------------------------------------------------- 1 | # WebSocket 2 | 3 | - [使用 WebSocket 服务](#use-websocket-server) 4 | - [处理握手](#hand-shake) 5 | - [连接处理器](#connection-handler) 6 | 7 | 8 | ## 使用 WebSocket 服务 9 | 10 | 开启 Http 的支持是使用 WebSocket 模块的前提,所以在使用 WebSocket 之前,我们先要确保已经把 `Lawoole\Http\HttpServiceProvider` 添加到了 `app.providers` 这个配置项中。 11 | 12 | 使用 `Lawoole\Websocket\WebsocketServerSocketHandler` 作为 `server.listens` 中的监听处理器能够让我们同时处理 Http 和 WebSocket 请求,所以我们能够在 Lawoole 中使用同一个端口处理两种不同的协议。 13 | 14 | 15 | ## 处理握手 16 | 17 | 握手是建立 WebSocket 连接的重要环节,也是通过鉴权等方式确定接受和拒绝连接的最佳时机,在 Lawoole 里,我们还将在这里指定对 WebSocket 连接的处理方式。 18 | 19 | 建立 WebSocket 连接的请求是一个 Http 请求,我们可以像普通 Http 请求一样来处理这个请求。我们需要在控制器或者其他请求处理方式里,通过 `HandShakeResponse::accept($request, $handler)` 或者 `HandShakeResponse::reject($request, $status)` 来选择接受或者拒绝这个 WebSocket 请求。 20 | 21 | 22 | ## 连接处理器 23 | 24 | 在接受 WebSocket 请求时,我们会通过 `accept($request, $handler)` 方法传递一个连接处理器对象。连接处理器需要实现 `Lawoole\Contracts\WebSocket\WebSocketHandler` 接口。 25 | 26 | 在连接处理器里,我们可以处理来自此连接的 WebSocket 请求,并能够通过 `$connection` 向客户端发送数据。如果采用相同的连接处理器处理多个请求,你可以通过 `$connection->getId()` 来区分它们。 27 | -------------------------------------------------------------------------------- /zh-Hant/documentation.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lawoole/docs/ae4e58033143f87ade009758b203b6141075f501/zh-Hant/documentation.md --------------------------------------------------------------------------------