PHPackages                             refink/refink - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. refink/refink

ActiveProject[Framework](/categories/framework)

refink/refink
=============

a php backend framework for game or app

2.2.4(5y ago)12142Apache-2.0PHPPHP &gt;=7.1.0

Since Mar 16Pushed 5y ago1 watchersCompare

[ Source](https://github.com/jiangjiping/refink)[ Packagist](https://packagist.org/packages/refink/refink)[ RSS](/packages/refink-refink/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (3)Used By (0)

### Refink协程框架特性

[](#refink协程框架特性)

- 支持基于http的restful api接口，自带类似laravel的静态路由、中间件
- 支持websocket单机或集群的消息路由(类似http的url路由)。只需要在对应的handler下写业务代码
- 支持分布式任务异步派发和消费, 支持消费进程内协程并发限流(control peak coroutine number) (具体配置和使用见下文)
- 支持数据库连接池, 连接池的连接都是有心跳检测自动保活机制，当前进支持redis和mysql
- 支持数据库ORM
- 高性能：和原生swoole非常接近，因为框架代码极其精简，带来的性能损耗忽略不计

### 使用方法

[](#使用方法)

- 使用composer安装项目:

```
composer create-project refink/refink

```

- 命令行启动server(终端挂起模式)

```
 refink/server start

```

- 命令行启动server(daemonize守护进程模式)

```
 refink/server start -d

```

### 如何访问后端地址？

[](#如何访问后端地址)

- 当server成功启动时，会如下输出

```
 ____       __ _       _
|  _ \ ___ / _(_)_ __ | | __
| |_) / _ \ |_| | '_ \| |/ /
|  _ <  __/  _| | | | |   <
|_| \_\___|_| |_|_| |_|_|\_\

**************************************************
http server       |  http://0.0.0.0:9501
websocket server  |  ws://0.0.0.0:9501
app log path      |  /var/log
swoole version    |  4.4.16
php version       |  7.2.24
**************************************************
press CTRL + C to stop.

```

假设您服务器对外可以访问的ip为: 192.168.1.122 则可访问:

```
http://192.168.1.122:9501/demo

```

- 访问其他路由时，确保mysql或redis的连接信息已正确配置

### 路由配置

[](#路由配置)

```
app/routes.php中有示例代码

```

### 如何同时支持http和websocket?

[](#如何同时支持http和websocket)

```
 $app = new Server("0.0.0.0", 9501, Server::SERVER_TYPE_HTTP | Server::SERVER_TYPE_WEBSOCKET );

```

### 关于env环境配置

[](#关于env环境配置)

- dev: php.ini添加配置APP\_ENV=dev，则框架会自动加载项目根目录的 config\_dev.php, 默认未配置也是加载它
- test: php.ini添加配置APP\_ENV=test, 则框架会自动加载项目根目录 config\_test.php
- prod: php.ini添加配置APP\_ENV=prod, 则框架会自动加载 config\_prod.php

### php-cli命令行执行业务代码

[](#php-cli命令行执行业务代码)

- 场景1：在linux crontab中执行的计划任务脚本
- 场景2：需要单独在终端执行的代码
- 使用方法: composer安装之后，项目根目录有个console可执行文件，这是php-cli下的入口文件, 单个可执行的php callable对象 本框架称其为 用户自定义的command

Usage:

```
 1、注册command命令:

\Refink\Command::register("migrate", [\App\Console\Migrate::class, 'run'], "迁移数据");

 2 、terminal执行：

 [~!#] /path/to/console migrate

 3、crontab配置
 * 2 * * * /path/to/console migrate

```

### 数据库基本操作

[](#数据库基本操作)

```
use Refink\Database\Pool\MySQLPool;
use Refink\Database\Pool\RedisPool;
