Download the PHP package kode/runtime without Composer
On this page you can find all versions of the php package kode/runtime. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Vendor kode
Package runtime
Short Description Unified runtime abstraction layer for modern PHP long-running applications
License MIT
Package runtime
Short Description Unified runtime abstraction layer for modern PHP long-running applications
License MIT
Please rate this library. Is it a good library?
Informations about the package runtime
kode/runtime —— 跨平台运行时抽象层
一个为现代 PHP 常驻内存应用设计的统一运行时抽象包 支持 Swoole、Swow、PHP Fiber(协程)、多进程、多线程、Console 及传统 CLI 模式 面向 PHP 8.1+,基于协变/逆变、readonly、match 等 PHP 8+ 新特性构建
📦 包信息
| 项目 | 内容 |
|---|---|
| 包名 | kode/runtime |
| PHP 版本 | ^8.1 |
| 许可证 | Apache-2.0 |
| 维护状态 | Active |
| GitHub | https://github.com/kodephp/runtime |
| Packagist | kode/runtime |
依赖包
| 包名 | 版本 | 说明 |
|---|---|---|
kode/context |
^2.0 |
协程/纤程上下文管理 |
kode/console |
^3.0 |
控制台输入输出(可选) |
🎯 设计目标
为构建 常驻内存型 PHP 框架 提供底层运行时抽象能力:
- 🔌 统一不同协程引擎(Swoole / Swow / Fiber)的 API 差异
- 🔄 提供一致的异步编程模型
- 🏗️ 支持多进程、多线程环境
- 🎨 集成 Console 控制台支持
- 🔒 协程安全的上下文管理
✅ 核心功能
| 功能 | 说明 |
|---|---|
| 🔍 运行环境检测 | 自动识别 Swoole、Swow、Fiber、Console、Process、Thread、CLI 模式 |
| 🔄 统一协程启动 | Runtime::async() 跨平台启动协程 |
| ⏱️ 统一 sleep API | Runtime::sleep() 支持微秒级休眠 |
| 📦 通道(Channel) | 跨平台协程间通信机制 |
| 🧩 defer 支持 | 函数退出时自动执行清理逻辑 |
| 🧠 上下文管理 | 基于 kode/context 的协程安全存储 |
| 🎮 Console 集成 | RuntimeCommand 命令基类,集成控制台输出 |
| 🛠️ 适配器模式 | 易于扩展新运行时 |
🚀 快速开始
1. 安装
2. 环境检测
3. 启动协程
4. Channel 通信
5. defer 清理资源
6. 多进程支持
7. Console 命令
🧱 架构设计
适配器模式
核心类
| 类名 | 说明 |
|---|---|
Runtime |
静态门面,提供全局访问点 |
RuntimeInterface |
运行时接口契约 |
RuntimeAdapterFactory |
适配器工厂类 |
ConsoleRuntime |
Console 环境适配器 |
SwooleRuntime |
Swoole 协程适配器 |
SwowRuntime |
Swow 协程适配器 |
FiberRuntime |
PHP Fiber 适配器 |
ProcessRuntime |
多进程适配器 |
ThreadRuntime |
多线程适配器 |
CliRuntime |
CLI 同步执行适配器 |
RuntimeCommand |
Console 命令基类 |
🔄 API 参考
Runtime 门面
RuntimeAdapterFactory
RuntimeCommand 基类
🧪 Channel 接口
🧪 兼容性
| 运行环境 | 支持 | 说明 |
|---|---|---|
| Swoole | ✅ | v4.8+,需启用协程 |
| Swow | ✅ | v1.5+ |
| PHP Fiber | ✅ | PHP 8.1+ |
| Console | ✅ | 集成 kode/console |
| 多进程 | ✅ | 基于 PCNTL |
| 多线程 | ⚠️ | 需 pthreads 扩展 |
| CLI | ✅ | 同步执行 |
🧪 测试
测试覆盖
- ✅ Runtime 门面测试
- ✅ ProcessRuntime 适配器测试
- ✅ ThreadRuntime 适配器测试
- ✅ Channel 接口测试
- ✅ 上下文管理测试
🛡️ 特性
- 类型安全:PHP 8.1+ 严格类型、readonly、final
- 内存管理:自动清理协程栈
- 异常处理:统一捕获协程异常
- 协程安全:基于
kode/context的上下文隔离
📁 目录结构
🙌 贡献
欢迎提交 PR 和 Issue!
请遵循 PSR-12 编码规范,编写单元测试。
📄 许可证
Apache License 2.0
kode/runtime—— 让 PHP 在任何运行时都如丝般顺滑 🚀
All versions of runtime with dependencies
PHP Build Version
Package Version
The package kode/runtime contains the following files
Loading the files please wait ...