Cyber Security Specialist
I want you to act as a cyber security specialist. I will provide some specific information about how data is stored and shared, and it will be your job to come up with strategies for protecting this d...
generic skill
Sign in to like and favorite skills
I want you to act as a cyber security specialist. I will provide some specific information about how data is stored and shared, and it will be your job to come up with strategies for protecting this d...
I want to act as a Statistician. I will provide you with details related with statistics. You should be knowledge of statistics terminology, statistical distributions, confidence interval, probabillit...
I want you to act as a scientific data visualizer. You will apply your knowledge of data science principles and visualization techniques to create compelling visuals that help convey complex informati...
sidebar: false sidebarDepth: 3
目录 [[TOC]]
Hyperf 本身是基于 Swoole 的生命周期,对于 自定义进程、worker进程、等都是CLI模式运行,当服务重启的时候,
如果有任务(http请求、异步任务、定时任务等)等正在处理,那么会出现不可预测的问题。
虽然框架提供了
信号处理器 ,但是依然不建议完全依赖该组件进行无脑重启。这里提供两个关于服务重启的方案:
K8S、Docker Swarm 等进行轮转重启。或者网关的流量进行切换。了解协程前,先了解下传统的
PHP-FPM 的工作模式。PHP-FPM 本质上是一个进程管理器,实现了 FastCGI 协议。
当请求发送到 Nginx 或者 Apache 后,Nginx 通过 FastCGI 协议将请求转发给 PHP-FPM 处理,PHP-FPM fork对应的 work
进程来执行 PHP 脚本。执行完后回收该进程。整个过程是 同步阻塞 的。当大量请求并发请求时,创建的进程会非常多,并且创建、销毁进程占用资源是非常大的。同时,多进程下会产生大量的 MySQL 连接,此时数据库
也会产生瓶颈。
为了解决传统FPM的痛点,我们容易想到的是单个进程内开启多个线程来处理多个请求或者并发问题,但是从代码级别上来说,PHP对线程支持并不友好,其次,多线程 有许多问题需要额外考虑,多线程读写加锁问题(CPU调度)、锁的颗粒度、死锁问题、线程异常可能导致整个进程崩溃。那么,这时就可以采用
协程 来解决问题。
当我们使用
Hyperf 作为纯 Http Server 时,我们应尽量在服务前使用网关(Gateway) 或者 Nginx等反向代理来进行流量管理。尽管 Hyperf
可以直接作为 Http Server。(╬ ̄皿 ̄)=○
如果作为异步任务处理服务使用时,我们应当注意服务重启相关。
::: warning  ̄□ ̄||
持续施工 🚧
规划中。。。
:::