gielfeldt / simple-worker
Simple worker and pool library.
dev-master
2016-05-30 16:20 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-11-09 20:28:14 UTC
README
Installation
To install the Simple Worker library in your project using Composer, first add the following to your composer.json
config file.
{ "require": { "gielfeldt/simple-worker": "^0.1" } }
Then run Composer's install or update commands to complete installation. Please visit the Composer homepage for more information about how to use Composer.
Simple Worker
This class allows you to queue operations in a pool and let them commence when ready.
Motivation
- De-coupling of the handling of guzzle asynchronous requests.
Using the Simple Worker library
Example
<?php namespace Gielfeldt\SimpleWorker\Example; require 'vendor/autoload.php'; use Gielfeldt\SimpleWorker\Pool; use Gielfeldt\SimpleWorker\Test\SimpleTestWorker; $pool = new Pool(['concurrency' => 1]); $time = microtime(true); $workers = []; for ($i = 0; $i < 10; $i++) { $workers[] = new SimpleTestWorker(uniqid(), 0.5); } print "Adding worker\n"; $pool->addWorkers($workers, function ($worker) use ($time) { $elapsed = microtime(true) - $time; print "\n$worker->key is ready! Elapsed time: $elapsed\n"; }); print "Processing workers\n"; $pool->process([ 'progress_callback' => function ($pool) { print "."; }, 'finish_callback' => function ($pool) { print "\n"; }, ]);
For more examples see the examples/ folder.
Features
- Queue operations in a pool.
Caveats
- Lots probably.