Download the PHP package evan-li/think-gateway without Composer

On this page you can find all versions of the php package evan-li/think-gateway. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package think-gateway

[TOC]

说明:

thinkphp5.0扩展: v0分支

thinkphp5.1扩展: v1分支

think-gateway扩展

基于tp5的gateway worker扩展

结构说明:

vendor (composer第三方库目录)
├─src                         核心代码目录
│  ├─Server.php               GatewayWorker扩展控制器文件
│  └─Events.php               默认的消息事件处理类
│
├─worker                      worker应用入口目录
│  ├─start                    服务启动目录
│  │  ├─config.php            注册服务启动文件
│  │  ├─start_register.php    注册服务启动文件
│  │  ├─start_gateway.php     gateway(网关)服务启动文件
│  │  └─start_business.php    业务服务启动文件
│  │  
│  ├─start.php                linux系统服务启动文件
│  └─start-for-win.bat        windows系统服务启动批处理文件
│
├─composer.json               composer 定义文件
├─LICENSE                     授权说明文件
└─README.md                   README 文件

使用介绍

安装:

  1. 创建thinkphp5项目

  2. 添加think-gateway依赖

    windows版本请使用evan-li/think-gateway-for-win包安装 :

如果没有使用过composer, 请先看 composer入门 , 可以使用composer中国镜像

启动服务:

  1. 创建一个Starter控制器,继承think\gateway\Server类,用来启动Worker

    application/worker/controller/Starter.php

  2. 创建worker应用入口

    将的`worker` 目录拷贝到项目根目录中, `worker` 目录中包含了服务启动所需要的文件
  3. 运行服务

    1. 在linux中, 首先切换到worker目录中, 执行命令:

    2. windows系统中, 直接执行worker目录中的 start-for-win.bat 批处理文件

到此为止, 我们的gateway-worker服务就跑起来啦 :smile:

消息处理

处理客户端发送的消息时, 增加一个MessageHandler类, 继承think\gateway\Events类, 并实现processMessage方法即可, 需要注意的是, processMessage方法是静态方法

增加MessageHandler类之后需要在Starter控制器中设置消息处理Handler:

app\worker\controller\Starter 类:

默认不设置消息处理类的时候, 调用的是Events类

app\worker\util\EventsHanler 类:

配置说明

配置文件位于worker/start/config.php文件中, 包含了各个服务的配置信息, 具体说明请查看文件: config.php

Windows中, 由于线程操作支持的问题, 所有的count (子worker启动的线程数) 配置都不会生效

分布式部署

如果需要分布式部署,我们可以通过worker/start目录中的对应的启动文件来控制启动哪个服务来控制启动哪个服务

分布式部署时根据需要的服务启动对应的服务

处于必要性考虑, register与gateway服务启动时不再加载tp5框架, 只有business服务会加载框架, 以方便在业务服务中使用框架的各种功能

Demo项目目录结构 (只做参考用):

使用正常的tp5目录结构, 框架本身相关的文件及目录不再展示

demo项目地址

类说明

Server类介绍

Server类是基于GatewayWorker的控制器扩展类, 使用自己的控制器继承Server类即可, 不需要实现任何方法, 只是起一个框架入口控制器的作用

服务相关的配置信息已归纳到配置文件中, 见: config.php 文件中

Events类介绍

think\gateway\Events类简单封装了一个连接的初始化事件响应,以及心跳信息忽略, 建议自定义的Events类直接继承 think\gateway\Events类并实现具体的 processMessage方法即可

$INIT_EVENT_KEY 属性

$INIT_EVENT_VALUE 属性

当客户端连接服务端后, 服务端会直接给客户端发送一个初始化事件, 将client_id返回 如$initEventKey设置为 action, $initEventValue 设置为 init, 则初始化后服务端给客户端发送一次格式为:{action: 'init', client_id: xxxxxx }的消息 客户端可以通过此事件获取client_id并到业务系统中将client_id注册到当前用户中


All versions of think-gateway with dependencies

PHP Build Version
Package Version
Requires workerman/gateway-worker Version ^3.0
topthink/think-helper Version >=1.0.4
topthink/think-installer Version ^2.0
topthink/framework Version 5.1.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package evan-li/think-gateway contains the following files

Loading the files please wait ....