tohidplus/paravel
Composer 安装命令:
composer require tohidplus/paravel
包简介
A package to run anonymous functions in parallel
README 文档
README
Parallel and Asynchronous functions in Laravel
A Laravel package to run anonymous functions in parallel or asynchronously without need to install any extension.
Installation
composer require tohidplus/paravel
Laravel
Publish the config file
php artisan vendor:publish --provider="Tohidplus\Paravel\ParavelServiceProvider"
Lumen
Copy the config file paravel.php from vendor/tohidplus/paravel to config directory and configure it in bootstrap/app.php
$app->configure('paravel'); // $app->register(Tohidplus\Paravel\ParavelServiceProvider::class);
Configuration
return [ 'artisan_path' => env('PARAVEL_ARTISAN_PATH', base_path('artisan')), ];
- Make sure the
artisanpath is correct.
Basic example
<?php use Tohidplus\Paravel\Facades\Paravel; $time = microtime(true); $results = Paravel::add('label_1',function (){ sleep(5); return 'Hello there'; })->add('label_2',function (){ sleep(5); return 'Hello again'; })->wait(); //Check the total execution time dump(microtime(true)-$time); // 5.* Secs
Run functions in background
<?php use Tohidplus\Paravel\Facades\Paravel; Paravel::add('label_1',function (){ return 'Hello there'; })->add('label_2',function (){ return 'Hello again'; })->run();
Helper methods
<?php use Tohidplus\Paravel\Facades\Paravel; $results = Paravel::add('label_1',function (){ return 'Hello there'; })->add('label_2',function (){ return 'Hello again'; })->wait(); // Get the item by label $results->get('label_1'); // Get result of item $results->resultOf('label_1'); // Get error of item $results->errorOf('label_1'); // Get status of item $results->statusOf('label_1'); // Check if all processes were succeeded. $results->succeeded(); // Check if any of the processes was failed. $results->failed();
Notice: Paravel comes with 100 milliseconds overhead by default. So before starting to use this package make sure the total execution time of processes is over 100ms.
Contribution
Please feel free to open issues or have contribution.
tohidplus/paravel 适用场景与选型建议
tohidplus/paravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 159 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 09 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 tohidplus/paravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tohidplus/paravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 159
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-09-04