1. Go to this page and download the library: Download toplan/task-balancer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
toplan / task-balancer example snippets
composer
//define a task
Balancer::task('task1', function($task){
//define a driver for current task like this:
$task->driver('driver_1 100 backup', function ($driver, $data) {
//do something here
...
//set whether run success/failure at last
if ($success) {
$driver->success();
} else {
$driver->failure();
}
//return some data you need
return 'some data you need';
});
//or like this:
$task->driver('driver_2', 90, function ($driver, $data) {
//...same as above..
})->data(['this is data 2']);
//or like this:
$task->driver('driver_3')
->weight(0)->backUp()
->data(['this is data 3'])
->work(function ($driver, $data) {
//...same as above..
});
});
//run the task
$result = Balancer::run('task1');