Download the PHP package stcer/syar without Composer
On this page you can find all versions of the php package stcer/syar. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package syar
为何用swoole来实现 Yar server
- 提升Yar服务效率
- 提升Yar服务稳定性
- 学习swoole, yar(在此感谢laruence,rango及swoole开发团队)
Requirements
- php5.4+
- ext-swoole 1.8.8+
- ext-msgpack 如果yar使用msgpack编码方式
Installation
Example
服务端 example\server.php
example/service/Test.php
命令行启动server.php
客户端
简单性能测试(benchmark)
测试脚本 example/benchmark/testSimple.php, 测试环境(虚拟机)
- cpu: i5 - 4460
- mem: 4G
- os: centos6.5
- php: php7(fpm: 20进程, swoole: 18进程(8 worker + 10 task)
脚本一共完成44次接口调用:
- 简单接口调用 2次
- 数据库查询接口调用2次
- 并发简单接口调用 20次
- 并发数据库查询接口调用 20次
在当前测试环境下,在使用syar批量接口请求,fpm环境下的执行时间大概是syar下的3 -- 6倍左右,
简单压力测试
测试脚本 example/benchmark/testConcurrent.php, 50%接口随机查询数据库(10000条数据, 主要为测试接口通信性能)
- syar 20个并发进程2.4w次接口调用, 用时2.6s秒左右, QPS 9300左右, 可能存在个别调用错误
- fpm 20个并发进程2.4w次接口调用, 用时15s秒左右, QPS 1600左右, 并产生大量Timeout was reached错误
扩展特性
接口批量请求
- 批量请求的接口,服务端使用多个任务进程并行执行
- 请求地址 http://{your_server_address}/multiple
- 调用方法名 function calls($requests); $requests参数格式 [请求1数组, 请求2数组, ...], 请求数据格式:['api' => ApiName, 'method' => MethodName, 'params' => []]
- 单个接口执行错误, 服务端记录错误日志, 返回['code' => CODE, 'error' => ERROR MESSAGE]格式数组, 客户端自行处理
客户端请求示例:
Protocol插件与Dispatcher插件
应用示例参考 example/server_plug.php, client_plug.php
Protocol触发事件:
- Protocol::EVENT_REQUEST_BEFORE, 请求开始触发, 可以提前响应客户端, 中断正常解析流程
- Protocol::EVENT_RESPONSE_AFTER, 请求结束触发, 可以适用请求结束之后的处理工作,比如写日志等
Dispatcher触发事件:
- Dispatcher::EVENT_REQUEST_BEFORE, Api接口执行前触发
- Dispatcher::EVENT_REQUEST_AFTER, Api接口执行后触发
投递任务到task进程异步执行
应用示例参考 example/taskManagerServer.php
- TaskMananger->regTask()
- TaskMananger->doTask()
- TaskMananger->doTasks()
- TaskMananger->doTasksAsync()
已知问题
- 未完成文档解析, 可使用自带的yar server显示文档
- 由于代码是从私有框架独立出来,可能存在未知bug
All versions of syar with dependencies
PHP Build Version
Package Version
Requires
php Version
>=5.4.16
ext-swoole Version >=1.8.8
ext-msgpack Version *
ext-swoole Version >=1.8.8
ext-msgpack Version *
The package stcer/syar contains the following files
Loading the files please wait ....