在SWOOLE模式下建议开启协程异步编程模式(用 rapphp最正确的姿势)
```
'swoole_http'=>[
'coroutine'=>true//使用协程进行异步编程
]
```
### 协程注意事项
*****
使用前建议你充分了解进程,线程,协程各个是什么东西,然后充分认识,异步编程和传统的 php 编程之间的区别
>因为数据库连接池的存在, 特别注意 Connection 对象不能注入到对象内,不然拿到的数据库连接会出错,导致严重的问题
记住 swoole 是内存型的所有对像在内存里(特别是 IOC 托管的对象),不会重复创建和销毁, 所以同一个对象中的 属性 可能会同时被多个用户的访问同时 访问到,并且当用户的一次访问结束时 对象的属性也不会别销毁(被 new 出来的对象,左右域只在方法内的对象没有问题啊)
下面的写法是绝对错的
```
class ContentService {
private $contentList;
public function listContent(){
$this->contentList= Content::select()->limit(1,10)->findAll();
}
public function renderContentUser(){
foreach ($this->contentList as $content) {
$content['user']=User::get($content->id);
}
}
}
class TestController{
private $contentService;
public function _initialize(ContentService $contentService) {
$this->contentService = $contentService;
}
public function test(){
$contents=$this->contentService->listContent();
$this->contentService->renderContentUser();
return $contents;
}
}
```
- 序言
- 开始
- 安装 RapPhp
- 应用目录
- 配置文件
- 入口类
- MVC架构
- 控制器基础
- 前置方法
- 拦截器
- 动态路由
- Request和Response
- Cookie和Session
- 模板引擎
- 请求缓存
- 流程图
- 数据库
- 基础使用
- 查询语法
- 查询操作
- where
- order
- limit
- lock
- fields
- join
- distinct
- having
- group
- force
- 查询方法
- 多数据源
- 数据库类型
- Record模型
- 使用Record
- 增删改
- 查找方法
- 数据类型
- 基本类型
- JSON 数据类型
- time
- date
- attach
- const
- 迭代操作
- record 更多方法
- 注入与转json
- 多级缓存
- 多数据源
- 模型生成
- 回调事件
- IOC控制反转
- Ioc基础概念
- 依赖注入
- Scope作用域
- 构造器
- 循环依赖
- AOP面向切面
- AOP使用
- 切面
- AopBuild
- 生成 aop 文件
- 事件勾子
- 执行循序
- Swoole
- Http服务器
- 用户进程
- Context上下文(重要)
- 协程
- 特色功能
- 限流器
- 连接池
- 数据库连接池
- Redis 连接池
- 通用连接池
- Rpc 远程调用
- Rpc服务提供方
- Rpc客户端
- 熔断器与服务降级
- Redis 分布式锁
- 其他功能
- 缓存
- redis
- 文件存储
- 存储简介
- 本地存储
- OSS存储
- 配置
- 日志
- 验证器
- FileUtil
- 数组Util
- Http工具
- 多语言
- 命令行
- 使用命令行
- 生成模型文件
- AOP动态文件生成
- swoole_http服务器
- 自定义命令行
- 异常与调试
- 异常抛出
- 异常处理
- 部署
- URL重写
- DOCKER 镜像(重要)
- 附录
- 回调事件
- 开发规范
- Swoole开发注意点
- 热点行更新排队机制
