wilbur/hyperf-soar
Composer 安装命令:
composer require wilbur/hyperf-soar
包简介
SQL optimizer and rewriter for Hyperf component.
README 文档
README
安装
# hyperf 1.* composer require wilbur/hyperf-soar:1.0 --dev # hyperf 2.* composer require wilbur/hyperf-soar --dev
发布配置文件
php bin/hyperf.php vendor:publish wilbur/hyperf-soar
下载 soar
# macOS * wget https://github.com/XiaoMi/soar/releases/download/0.11.0/soar.darwin-amd64 -O vendor/bin/soar # linux * wget https://github.com/XiaoMi/soar/releases/download/0.11.0/soar.linux-amd64 -O vendor/bin/soar # windows * wget https://github.com/XiaoMi/soar/releases/download/0.11.0/soar.windows-amd64 -O vendor/bin/soar # authorization * chmod +x vendor/bin/soar
env 增加配置
SOAR_ENABLED=true SOAR_TEST_DSN_DISABLE=false SOAR_PATH=your_soar_path SOAR_TEST_DSN_HOST=127.0.0.1 SOAR_TEST_DSN_PORT=3306 SOAR_TEST_DSN_DBNAME=yourdb SOAR_TEST_DSN_USER=root SOAR_TEST_DSN_PASSWORD= SOAR_REPORT_TYPE=json
执行方式
在
hyperf start后,监听QueryExec事件, 在全局的响应中插入了监听到的sql列表对应的优化建议 目前只对response()->json()进行了插入
样例
{
"code": 200,
"message": "success",
"data": {
"id": 0,
"title": "谢谢参与",
"type": "none",
"value": "0"
},
"soar": [
{
"query": "select snapshot from u_awards where user_id = '41' and json_unquote(json_extract(snapshot, '$.\"type\"')) = 'cash'",
"explain": [
{
"Item": "FUN.001",
"Severity": "L2",
"Summary": "避免在 WHERE 条件中使用函数或其他运算符",
"Content": "虽然在 SQL 中使用函数可以简化很多复杂的查询,但使用了函数的查询无法利用表中已经建立的索引,该查询将会是全表扫描,性能较差。通常建议将列名写在比较运算符左侧,将查询过滤条件放在比较运算符右侧。也不建议在查询比较条件两侧书写多余的括号,这会对阅读产生比较大的困扰。",
"Case": "select id from t where substring(name,1,3)='abc'",
"Position": 0,
"Score": 90
}
]
},
{
"query": "select id, v, amount, balance, type, value, image, title from awards where balance > '0' and is_enabled = '1'",
"explain": [
{
"Item": "OK",
"Severity": "L0",
"Summary": "OK",
"Content": "OK",
"Case": "OK",
"Position": 0,
"Score": 100
}
]
},
{
"query": "select id, user_id, value from user_points where user_points.user_id in (41)",
"explain": [
{
"Item": "OK",
"Severity": "L0",
"Summary": "OK",
"Content": "OK",
"Case": "OK",
"Position": 0,
"Score": 100
}
]
},
{
"query": "update u_points set value = value - 20, u_points.updated_at = '2021-01-22 16:05:06' where id = '26'",
"explain": [
{
"Item": "OK",
"Severity": "L0",
"Summary": "OK",
"Content": "OK",
"Case": "OK",
"Position": 0,
"Score": 100
}
]
},
{
"query":"insert into u_awards (award_id, snapshot, client_ip, used_point, expired_at, extra, user_id, updated_at, created_at) values ('0', '{\"id\":0,\"v\":100,\"type\":\"none\",\"image\":\"\",\"value\":\"0\",\"title\":\"\谢\谢\参\与\"}', '127.0.0.1', '20', '2021-04-22 16:05:06', '[]', '41', '2021-01-22 16:05:06', '2021-01-22 16:05:06')",
"explain": [
{
"Item": "LIT.001",
"Severity": "L2",
"Summary": "用字符类型存储IP地址",
"Content": "字符串字面上看起来像IP地址,但不是 INET_ATON() 的参数,表示数据被存储为字符而不是整数。将IP地址存储为整数更为有效。",
"Case": "insert into tbl (IP,name) values('10.20.306.122','test')",
"Position": 207,
"Score": 90
}
]
}
]
}
感谢
wilbur/hyperf-soar 适用场景与选型建议
wilbur/hyperf-soar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 92 次下载、GitHub Stars 达 23, 最近一次更新时间为 2019 年 10 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「hyperf」 「soar」 「php-soar」 「wilbur」 「hyperf-soar」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wilbur/hyperf-soar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wilbur/hyperf-soar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wilbur/hyperf-soar 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SQL optimizer and rewriter(assisted SQL tuning). - SQL 优化器和重写器(辅助 SQL 调优)。
An async event for hyperf.
SQL optimizer and rewriter for laravel. - laravel 的 SQL 优化器和重写器。
php hyperf xxljob
SForum
统计信息
- 总下载量: 92
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 23
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-10-29