2017 © Pedro Peláez
 

library simple-worker

Simple worker and pool library.

image

gielfeldt/simple-worker

Simple worker and pool library.

  • Monday, May 30, 2016
  • by gielfeldt
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Simple Worker

[Build Status][8] Test Coverage [Scrutinizer Code Quality][7] Code Climate, (*1)

Latest Stable Version Latest Unstable Version License Total Downloads, (*2)

Installation

To install the Simple Worker library in your project using Composer, first add the following to your composer.json config file., (*3)

{
    "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., (*4)

Simple Worker

This class allows you to queue operations in a pool and let them commence when ready., (*5)

Motivation

  1. 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., (*6)

Features

  • Queue operations in a pool.

Caveats

  1. Lots probably.

The Versions

30/05 2016

dev-master

9999999-dev https://github.com/gielfeldt/simple-worker

Simple worker and pool library.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Thomas Gielfeldt

queue worker pool