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.
统计信息
- 总下载量: 159
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-09-04