Download the PHP package kode/fibers without Composer

On this page you can find all versions of the php package kode/fibers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package fibers

🚀 Kode/fibers – 高性能 Fiber 线程池与协程调度器

面向 PHP 8.1+ 的高性能 Fiber 纤程客户端,兼容主流框架并提供可降级、可诊断、可扩展的并发执行能力。


✅ 特性概览

📖 项目背景

kode/fibers 旨在为 Laravel、Symfony、Yii3、ThinkPHP8 及自建框架提供统一的纤程运行时能力,减少业务接入并发模型时的改造成本。\ 项目重点解决三类问题:PHP 版本差异(尤其是 PHP<8.4 的析构限制)、生产场景下的并发治理(池化、超时、重试、通信)、以及跨框架可移植性(统一配置与 CLI 初始化)。

⚙️ PHP 8.5 兼容与便捷 API

新增便捷入口以降低接入成本并兼容未来 PHP 8.5 运行时能力:

新增健壮架构 API

对应文档:


📦 安装

框架快速集成(可选)

使用内置命令工具初始化框架配置:

各框架特定命令:

框架 命令 说明
Laravel php artisan vendor:publish --tag=fibers-config 生成 config/fibers.php
Symfony bin/console fibers:install 创建 config/packages/fibers.yaml
Yii3 php yii fibers/setup 初始化模块配置
ThinkPHP8 php think fibers:config 生成 config/fibers.php
其他/原生 vendor/bin/fibers init 交互式创建配置文件

环境要求检查

安装完成后,可以运行诊断命令检查环境兼容性:

诊断结果将显示PHP版本、禁用函数、必要扩展等信息,并给出优化建议。


🧱 架构设计原则

本包采用 “轻量内核 + 插件扩展” 设计:

所有组件均实现 PSR 标准,支持 DI 容器注入。


🧪 快速开始

1. 基础使用:一键启动纤程任务

使用门面或辅助函数快速启动纤程:

2. 使用纤程池(推荐生产环境)

纤程池支持资源复用、超时控制和错误重试:


🧰 核心功能详解

✅ 1. PHP 版本兼容性处理(含析构限制规避)

⚠️ PHP 8.4 之前:不允许在 __destruct() 中调用 Fiber::suspend()

我们通过静态分析和运行时检测自动处理此问题,确保在不同PHP版本中都能正常运行:

自动降级策略:

条件 行为
PHP < 8.1 抛出异常,不支持
PHP >= 8.1 && < 8.4 启用延迟析构任务队列,安全处理析构中的suspend操作
PHP >= 8.4 正常允许在析构函数中使用suspend操作

可通过配置关闭严格模式:

✅ 2. 纤程池(Fiber Pool)高级用法

获取 CPU 数量(用于动态配置)

自定义池配置示例

支持的操作类型

类型 是否支持 示例
MySQL PDO::query() in fiber
PgSQL \PDO\pg_connect()
Redis \Redis, \Predis\Client
HTTP file_get_contents, curl_exec, Guzzle
文件 IO fopen, fwrite(需异步驱动)
Queue Channel / MessageQueue
Sleep usleep() 被拦截为非阻塞

💡 提示:建议配合异步 I/O 扩展如 swowswoole 使用以获得最佳性能。

✅ 3. 多框架适配方案

Kode/fibers提供了统一的API和自动检测机制,可以无缝集成到各种PHP框架中:

统一配置结构 (config/fibers.php)

框架集成示例

Laravel 集成:

Symfony 集成:

Yii3 框架集成:

ThinkPHP8 框架集成:

原生 PHP 项目:

✅ 4. PHP 8.1 原生注解 + IDE 可识别设计

Kode/fibers充分利用PHP 8.1的原生注解功能,提供更好的IDE支持和类型安全:

使用 Attribute 实现元数据标记

PHPDoc 辅助 IDE 提示

✅ 在 PhpStorm / VSCode + Intelephense 中均可获得完整补全!

自动类型推断与验证

Kode/fibers通过PHP 8.1的类型系统和注解,可以在开发阶段捕获潜在问题:

✅ 5. 通信机制:Channel 与 Event Bus

Kode/fibers提供了强大的纤程间通信机制,包括Channel(类似Go Channel)和Event Bus(发布/订阅模式):

创建通信通道(类似 Go Channel)

发布/订阅模型(Event Bus)

✅ 6. 禁用函数检测与环境诊断

Kode/fibers提供了全面的环境检测功能,可以识别潜在的兼容性问题:

检测黑名单函数

常见禁用函数影响

函数 影响 建议
pcntl_* 多进程冲突 关闭或隔离使用
set_time_limit 可能中断 suspend 使用 @ini_set 局部关闭
exec, shell_exec 阻塞调用 替换为异步执行器
sleep, usleep 阻塞主线程 已被 Fiber 内部重写为非阻塞
exit, die 终止整个进程 避免使用,改用抛出异常
header, session_start 可能破坏上下文 在主纤程中使用,或使用上下文管理器

✅ 我们会在初始化时尝试模拟这些函数的安全替代品。


📘 使用场景指南

🧩 何时使用 Fiber::run()?(一键协程)

适用于小规模并发请求,无需长期维护状态:

✅ 优点:零配置、无副作用\ ❌ 缺点:无法复用、无资源管控


🏗️ 何时使用 FiberPool?(生产推荐)

适用于高并发服务,如微服务网关、批量任务处理器:

✅ 支持:


🛠️ CLI 命令列表

Kode/fibers提供了一系列命令行工具,方便开发和管理:

常用命令选项


🔄 自动降级机制

kode/fibers 支持智能降级,根据已安装的依赖包自动选择最佳实现:

安装方式

功能对比

功能 最小安装 完整安装
核心 Fiber API ✅ 完整支持 ✅ 完整支持
HTTP 客户端 原生 cURL kode/http-client + PSR-7
命令行工具 基础输出 kode/console 完整功能
Facade 模式 基础静态代理 kode/facade 完整功能
上下文传递 ✅ 完整支持 ✅ 完整支持
连接池 ✅ 完整支持 ✅ 完整支持

使用示例


🧩 功能实现状态

✅ 已实现功能

详细开发计划见 路线图文档。


📚 参考资料


🙌 贡献者

欢迎提交 PR!请确保:


Maintained by Byte Team - Kode PHP Lab\ 🌐 https://github.com/Kode-php/fibers



All versions of fibers with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
guzzlehttp/psr7 Version ^2.8
kode/context Version ^2.1
kode/aop Version ^2.0
kode/attributes Version ^1.0
kode/facade Version ^2.0
kode/http-client Version ^2.1
kode/console Version ^2.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package kode/fibers contains the following files

Loading the files please wait ...