DoBee 是基于 FastD 组件生态构建的最小 PHP API 框架骨架,支持 Swoole 与 FastCGI 运行。
- 最小可运行骨架:安装后只有欢迎接口
- PSR-7 / PSR-15 / PSR-17 标准
- Swoole HTTP Server 与 FastCGI 双运行时
- 默认包含 Cache / MedooDB 组件
- 可选 Demo 包:
fastd/dobee-demo - 构造器注入 / 路由 resolver 由 FastD 核心提供
- PHP >= 8.4.1
- ext-json
- ext-pdo(MedooDB 依赖)
- ext-swoole >= 6.0
composer create-project fastd/dobee myapp
cd myappphp bin/server start
curl http://127.0.0.1:9527/php -S 127.0.0.1:8099 -t web
curl http://127.0.0.1:8099/响应:
Hello FastD and goodbye FastD [fastcgi]
方括号中为当前执行环境(如 fastcgi、swoole、testcase),用于区分运行时。
dobee/
├── config/
│ ├── cache.php # 缓存池 / HTTP 缓存配置(含注释示例)
│ ├── command.php # 控制台命令(按需加载 demo)
│ ├── database.php # SQLite/MySQL 配置(含注释示例)
│ ├── listener.php # 事件监听
│ ├── process.php # 自定义进程 / 信号监听
│ ├── service.php # 服务提供者(按需加载 demo)
│ ├── session.php # Session 配置
│ └── swoole.php # Swoole 服务配置
├── routes/
│ └── web.php # 路由(仅欢迎接口)
├── src/
│ ├── bootstrap.php # 应用引导
│ └── Http/Controller/ # 应用 Controller
├── tests/Feature/ # 欢迎接口测试
├── web/index.php # FastCGI 入口
├── bin/server # Swoole 启动脚本
└── composer.json
Demo 能力已拆分到独立包:
https://github.com/fastdlabs/dobee-demo
默认作为 require-dev 安装,包含:
- Session
- SSE / AI Mock Stream
- RequestId Middleware
- 构造器注入 / Resolver
- Cache(file adapter)
- Database(SQLite / MedooDB)
- Swoole Server / 自定义 Listener
- Console Command
- Process / Signal
- 演示页面
/demo/*.html
composer require --dev fastd/dobee-demo安装脚本会在宿主的 config/service.php、config/swoole.php 中注入 Demo Provider 和监听端口;dobee 骨架本身保持最简,不需要复制 Demo 代码。
Demo HTML 页面建议通过 CGI 打开:
php -S 127.0.0.1:8099 -t webhttp://127.0.0.1:8099/demo/index.html
Swoole 模式:
php bin/server startDemo 首页:
- 左侧:Demo 列表
- 中间:点击 Demo 后直接嵌入展示,不跳转
- 右侧:CGI / Swoole 切换、启动命令、当前 API 域名
HTML 页面固定从当前 CGI URL 加载;API 请求按右侧选择切换:
| 模式 | API 域名 |
|---|---|
| CGI | 当前 URL 域名 |
| Swoole | config/swoole.php 的 servers.http.host / port |
Demo 页面右下角会显示页面域名、实际 API 域名和最近一次请求,便于区分两种运行环境。
完整 Demo 路由与说明见:
生产环境使用 --no-dev 安装时不会引入 Demo 路由、中间件或代码:
composer install --no-dev如果使用 composer create-project,默认会安装 dev 依赖;不需要 Demo 时可直接移除:
composer remove --dev fastd/dobee-demo仓库提供生产用 Dockerfile,镜像内包含 PHP 8.4、Swoole 6、PDO 和生产依赖。
docker build -t fastd-dobee:1.4.3 .docker run -d \
--name fastd-dobee \
-p 9527:9527 \
-v "$PWD/runtime:/app/runtime" \
fastd-dobee:1.4.3验证:
curl http://127.0.0.1:9527/- 生产配置通过挂载
config/或环境变量注入,不要把密钥打进镜像; runtime/必须挂载,否则容器重建会丢失日志、缓存和 pid;- 容器内默认将 Swoole 监听地址改为
0.0.0.0;如果自行挂载config/swoole.php,也要保持0.0.0.0; runtime/对容器内www-data用户可写。
镜像 tag 与发布版本对应:
docker build -t registry.example.com/fastd-dobee:1.4.3 .
docker push registry.example.com/fastd-dobee:1.4.3回滚时运行上一版本镜像即可。
composer install
bin/phpunit --no-coverage
bin/phpstan analyse --no-progressMIT
config/ 下保留了完整的配置示例与注释:
cache.php:文件、PHP、Redis、Memcached、HTTP 缓存中间件database.php:SQLite(默认)、MySQL、PostgreSQLsession.php:Session handler、Cookie、TTL、Swoole Tablecommand.php:控制台命令注册(Demo 条件加载)process.php:Worker 与信号监听(Demo 条件加载)swoole.php:多端口 Listener、Stats、Swoole 设置service.php/listener.php:服务与事件监听
Demo 命令:
php bin/console demo:hello
# Hello from fastd/dobee-demo command
php bin/process
# [demo] worker started: demo (pid=...) Hello FastD from constructor injectionconfig/service.php 默认保持为空。
安装 fastd/dobee-demo 后,Composer 的 post-install-cmd / post-update-cmd
会直接调用 Demo 包的 scripts/install.php:
- 读取并校验原配置
- 在
return数组内定点注入 Demo spread 表达式 - 只有执行脚本时才写入
demo: fastd/dobee-demo注释 - 用户已有配置与注释不变
- 未安装 Demo 时注入内容通过
class_exists()自动失效