symplely/thread_queue
Composer 安装命令:
composer require symplely/thread_queue
包简介
An simply `uv_queue_work` wrapper API to manage a pool of threads, for parallel PHP execution
README 文档
README
An simply uv_queue_work wrapper API to manage a pool of threads, for parallel PHP execution.
Table of Contents
This package uses features of libuv, the PHP extension ext-uv of the Node.js library. It's uv_queue_work function is used to create Threads.
Installation
composer require symplely/thread_queue
This package will require libuv features, do one of the following to install.
For Debian like distributions, Ubuntu...
apt-get install libuv1-dev php-pear -y
For RedHat like distributions, CentOS...
yum install libuv-devel php-pear -y
Now have Pecl auto compile, install, and setup.
pecl channel-update pecl.php.net pecl install uv-beta
For Windows, stable PHP versions are available from PECL.
Directly download latest from https://windows.php.net/downloads/pecl/releases/uv/
Extract libuv.dll to same directory as PHP binary executable, and extract php_uv.dll to ext\ directory.
Enable extension php_uv.dll in php.ini
cd C:\Php Invoke-WebRequest "https://windows.php.net/downloads/pecl/releases/uv/0.2.4/php_uv-0.2.4-7.2-ts-vc15-x64.zip" -OutFile "php_uv-0.2.4.zip" #Invoke-WebRequest "https://windows.php.net/downloads/pecl/releases/uv/0.2.4/php_uv-0.2.4-7.4-ts-vc15-x64.zip" -OutFile "php_uv-0.2.4.zip" 7z x -y php_uv-0.2.4.zip libuv.dll php_uv.dll copy php_uv.dll ext\php_uv.dll del php_uv.dll del php_uv-0.2.4.zip echo extension=uv >> php.ini
Usage
include 'vendor/autoload.php'; use Async\Threads\Thread; $thread = new Thread(); $counter = 0; $t1 = $thread->create_ex(function () { print "Running Thread: 1\n"; return 2; })->then(function (int $output) use (&$counter) { $counter += $output; })->catch(function (\Throwable $e) { print $e->getMessage() . PHP_EOL; }); $t1->join(); // Or $t1->cancel(); print_r($t1->result()); // Or print_r($t1->exception());
Event hooks
When creating Threads processes, you'll get an instance of TWorker returned.
You can add the following event callback hooks on a Thread instance.
$thread = new Thread($function, ...$args) $worker = $thread->create($thread_id /* string or int */, function () { }, ...$arguments) ->then(function ($result) { // On success, `$result` is returned by the thread. }) ->catch(function ($exception) { // When an exception is thrown from within a thread, it's caught and passed here. }); $worker = $thread->create_ex(function () { }, ...$arguments) ->then(function ($result) { // On success, `$result` is returned by the thread. }) ->catch(function ($exception) { // When an exception is thrown from within a thread, it's caught and passed here. });
Contributing
Contributions are encouraged and welcome; I am always happy to get feedback or pull requests on Github :) Create Github Issues for bugs and new features and comment on the ones you are interested in.
License
The MIT License (MIT). Please see License File for more information.
symplely/thread_queue 适用场景与选型建议
symplely/thread_queue 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 49 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 03 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「async」 「parallel」 「asynchronous」 「Thread」 「libuv」 「uv_queue_work」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 symplely/thread_queue 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 symplely/thread_queue 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 symplely/thread_queue 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asynchronous coroutines for PHP 7.
The bundle for easy using json-rpc api on your project
An async event for hyperf.
Sequential way to run Symfony Processes in parallel
Symfony ResqueBundle
Generic PHP Threads library using only pure PHP
统计信息
- 总下载量: 49
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 15
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-07