基础
环境配置
# docker php 内安装扩展
pecl install redis-5.3.7
docker-php-ext-enable redis
pecl install swoole(5.0.0)
docker-php-ext-enable swoole
ERROR Swoole short function names must be disabled before the server starts, please set swoole.use_shortname='Off' in your php.ini.
安装
composer create-project hyperf/hyperf-skeleton hyperf
启动
php bin/start.php start
# 默认端口 9501
端口被占用
apt-get install net-tools
netstat -anp | grep 9501
root@9858811b2700:/wwwroot/hyperf.loc# netstat -anp | grep 9501
tcp 0 0 0.0.0.0:9501 0.0.0.0:* LISTEN 422/skeleton.Master
root@9858811b2700:/wwwroot/hyperf.loc# kill -9 422
.env 配置
CONFIG_CENTER_ENABLE = false
热重载
php bin/hyperf.php server:watch
发布项目的时候,也可以模拟docker集群的发布过程。
发布新的容器
添加对应的dns解析
卸载将要停止容器的dns解析
停止对应的容器
所以,可以写一个脚本来处理。
切换服务端口启动项目
刷新nginx到新的端口
去掉老的nginx映射
关掉老的服务
Hyperf 生产环境, 不上Swarm, 不上 k8s, 如何做热更新?
phpStorm扩展:
php annotations
routes 路由
注解
路由定义了解注解
依赖注入了解注解的实现
Ioc
DI:即依赖注入,对象之间依赖关系由容器在运行期决定,由容器动态的将依赖关系注入到对象之中
hyperf/di组件提供依赖注入
hyperf AOP
Aspect 会在runtime/container/proxy 下生成缓存文件,只生成一次,更改代码需要手动删除
微服务
网关
服务中心
Nacos

消息队列
分布式事务
bug,登录的时候输入账号和密码,如果先输入账号,后输入密码,就能登录成功,先输入密码,后输入账号,就不能成功
php 语言 + hyperf 微服务 框架的完整微服务demo
Packagist: dtm/dtm-client
https://packagist.org/packages/dtm/dtm-client
https://github.com/dtm-php/dtm-client
use DtmClient\Saga
Hyperf RT
https://packagist.org/packages/windawake/hyperf-reset-transaction
Other
PHP微服务集群搭建
https://segmentfault.com/a/1190000020421333
一文详解微服务架构
https://www.cnblogs.com/skabyy/p/11396571.html
完整的php微服务案例
https://learnku.com/articles/68366
IT老齐的架构300讲
https://download.csdn.net/course/detail/35847?spm=1003.2449.3001.8294.1
强一致性的分布式事务几种模式对比
https://learnku.com/articles/63797
如何保障微服务架构下的数据一致性?
https://cloud.tencent.com/developer/article/1459734
https://blog.csdn.net/jinxinxin1314/article/details/108595301