2017 © Pedro Peláez
 

library beanstalk

Library for handling beanstalk connections.

image

phlib/beanstalk

Library for handling beanstalk connections.

  • Tuesday, February 13, 2018
  • by letssurf
  • Repository
  • 3 Watchers
  • 8 Stars
  • 790 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 8 Open issues
  • 23 Versions
  • 10 % Grown

The README.md

phlib/beanstalk

Code Checks Codecov Latest Stable Version Total Downloads Licence, (*1)

Beanstalkd library implementation., (*2)

Install

Via Composer, (*3)

``` bash $ composer require phlib/beanstalk, (*4)


## Basic Usage ``` php <?php use Phlib\Beanstalk\Connection; // producer $beanstalk = new Connection('127.0.0.1'); $beanstalk->useTube('my-tube'); $beanstalk->put(array('my' => 'jobData'));

``` php <?php use Phlib\Beanstalk\Connection;, (*5)

// consumer $beanstalk = new Connection('127.0.0.1'); $beanstalk->watch('my-tube') ->ignore('default'); $job = $beanstalk->reserve(); $myJobData = $job['body']; $beanstalk->delete($job['id']);, (*6)


## Connection configuration |Name|Type|Required|Default|Description| |----|----|--------|-------|-----------| |`host`|*String*|Yes| |Hostname or IP address.| |`port`|*Integer*|No|`11300`|Beanstalk's port.| |`options`|*Array*|No|`<empty>`|Connection options for Beanstalk.| ### Options |Name|Type|Default|Description| |----|----|-------|-----------| |`timeout`|*Integer*|`60`|The connection timeout.| ## Pool configuration |Name|Type|Required|Default|Description| |----|----|--------|-------|-----------| |`connections`|*ConnectionInterface[]*|Yes| |Array of server connections.| |`retryDelay`|*Integer*|No|`600`|How long to delay retrying a connection for after an error.| |`logger`|*LoggerInterface*|No| |Optional Logger to capture connection failures.| ## Factory The factory allows for easy setup of the objects. This especially useful when creating a pool of beanstalk servers. The following example lists the various ways it can be used. The configuration examples in the command line section are created using the factory. ```php $factory = new \Phlib\Beanstalk\Factory(); $beanstalk = $factory->create('localhost'); $beanstalk = $factory->createFromArray([ 'host' => 'localhost', ]); $beanstalk = $factory->createFromArray([ ['host' => '10.0.0.1'], ['host' => '10.0.0.2'], ['host' => '10.0.0.3'], ]);

Factory Configuration

The configuration options are as specified above. With the exception that when creating a pool there is an optional enabled., (*7)

$factory = new \Phlib\Beanstalk\Factory();

$beanstalk = $factory->createFromArray([
    ['host' => '10.0.0.1', 'enabled' => true],
    ['host' => '10.0.0.2', 'enabled' => false],
    ['host' => '10.0.0.3', 'enabled' => true],
]);

Pool

The pool allows for work to be pushed to and retrieved from multiple servers. The pool implements the connection interface., (*8)

use Phlib\Beanstalk\Connection;
use Phlib\Beanstalk\Pool;

$connections = [
    new Connection('10.0.0.1'),
    new Connection('10.0.0.2'),
    new Connection('10.0.0.3'),
    new Connection('10.0.0.4'),
];
$logger = new MyLogger();
$pool = new Pool($connections, 120, $logger);

$pool->useTube('my-tube');
$pool->put(array('my' => 'jobData1')); // )
$pool->put(array('my' => 'jobData2')); // )-> distributed between random servers
$pool->put(array('my' => 'jobData3')); // )

Alternative way to create a Pool, using the Factory to construct the connections:, (*9)

use Phlib\Beanstalk\Factory;
use Phlib\Beanstalk\Pool;

$connections = (new Factory())->createConnections([
    ['host' => '10.0.0.1', 'enabled' => true],
    ['host' => '10.0.0.2', 'enabled' => false],
    ['host' => '10.0.0.3', 'enabled' => true],
]);
$logger = new MyLogger();
$pool = new Pool($connections, 120, $logger);

Command Line Script

./vendor/bin/beanstalk

Running the script will provide you with a list of options. Most are self-explanatory. By default no configuration is required, the script will default to localhost., (*10)

Command Line Configuration

There are 2 ways of specifying a configuration., (*11)

  1. Create a file called beanstalk-config.php either in /app/root/ or /app/root/config/.
  2. Create a file with a name of your choosing and specify it using the command option -c /path/to/my/config.php.

The file must return an array containing the beanstalk configuration. This configuration will be passed to the Factory to create an instance., (*12)

return [
    'host' => '10.0.0.1',
    'port' => 11300
];
// pool configuration
return [
    [
        'host' => '10.0.0.1',
        'port' => 11300,
    ],
    [
        'host' => '10.0.0.2',
        'port' => 11300,
    ],
    [
        'host' => '10.0.0.3',
        'port' => 11300,
        'enabled' => false,
    ],
];
require_once 'my/app/bootstrap.php';

$app = new MyApp();
return $app['config']['beanstalk'];

License

This package is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version., (*13)

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details., (*14)

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/., (*15)

The Versions

13/02 2018

dev-master

9999999-dev https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

13/02 2018

1.0.14

1.0.14.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

30/10 2017

1.0.13

1.0.13.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

21/08 2017

dev-version2

dev-version2 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

27/01 2017

1.0.12

1.0.12.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

01/12 2016

1.0.11

1.0.11.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

14/10 2016

1.0.10

1.0.10.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

21/07 2016

1.0.9

1.0.9.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

11/07 2016

1.0.8

1.0.8.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

08/07 2016

1.0.7

1.0.7.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

05/07 2016

1.0.6

1.0.6.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

08/06 2016

1.0.5

1.0.5.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

03/06 2016

1.0.4

1.0.4.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

07/03 2016

1.0.3

1.0.3.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

19/02 2016

1.0.2

1.0.2.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

15/12 2015

dev-stats-model

dev-stats-model https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

14/12 2015

1.0.1

1.0.1.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

09/12 2015

1.0.0

1.0.0.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

24/11 2015

0.2.1

0.2.1.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

20/11 2015

0.2

0.2.0.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

06/11 2015

0.1.2

0.1.2.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

06/11 2015

0.1.1

0.1.1.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool

04/11 2015

0.1

0.1.0.0 https://github.com/phlib/beanstalk

Library for handling beanstalk connections.

  Sources   Download

MIT

The Requires

 

The Development Requires

by James Dempster
by Luke Richards

queue beanstalk job pool