Beanstalk\Pool Class Ref

class Beanstalk\Pool
Description:Beanstalkd connection pool
Author:Joshua Dechant <jdechant@shapeup.com>
$beanstalk = (new \Beanstalk\Pool)
    ->addServer('localhost', 11300)
    ->useTube('my-tube');
$beanstalk->put('Hello World!');

Class Methods

Beanstalk\Pool::addServer($host[, $port = 11300])
Description:

Add a beanstalkd server to the pool

Parameters:
  • $host (string) – Server host
  • $port (integer) – Server port
Returns:

self

Beanstalk\Pool::close()
Description:Close all connections in the pool
Beanstalk\Pool::connect()
Description:Establish a connection to all servers in the pool
Beanstalk\Pool::getConnections()
Beanstalk\Pool::getLastConnection()
Beanstalk\Pool::getServers()
Description:Get the Beanstalkd server addresses in the pool
Returns:array Beanstalkd server addresses in the format “host:port”
Beanstalk\Pool::getTimeout()
Description:Get the current connection timeout
Returns:float Current connection timeout
Beanstalk\Pool::ignoreTube($tube)
Description:

Ignore command

Parameters:
  • $tube (string) – Tube to remove from the watch list
Returns:

self

The “ignore” command is for consumers. It removes the named tube from the watch list for the current connection.

Beanstalk\Pool::kick($bound)
Description:

Kick command

Parameters:
  • $bound (integer) – Upper bound on the number of jobs to kick. Each server will kick no more than $bound jobs.
Returns:

integer The number of jobs actually kicked

The kick command applies only to the currently used tube. It moves jobs into the ready queue. If there are any buried jobs, it will only kick buried jobs. Otherwise it will kick delayed jobs

Beanstalk\Pool::listTubes()
Description:The list-tubes command returns a list of all existing tubes
Beanstalk\Pool::pauseTube($tube, $delay)
Description:

The pause-tube command can delay any new job being reserved for a given time

Parameters:
  • $tube (string) – The tube to pause
  • $delay (integer) – Number of seconds to wait before reserving any more jobs from the queue
Returns:

boolean

Throws:

BeanstalkException

Beanstalk\Pool::put($message[, $priority = 65536, $delay = 0, $ttr = 120])
Description:

The “put” command is for any process that wants to insert a job into the queue

Parameters:
  • $message (mixed) – Description
  • $priority (integer) – Job priority.
  • $delay (integer) – Number of seconds to wait before putting the job in the ready queue.
  • $ttr (integer) – Time to run. The number of seconds to allow a worker to run this job.
Beanstalk\Pool::reserve([$timeout = null])
Description:

Reserve command

Parameters:
  • $timeout (integer) – Wait timeout in seconds

This will return a newly-reserved job. If no job is available to be reserved, beanstalkd will wait to send a response until one becomes available. Once a job is reserved for the client, the client has limited time to run (TTR) the job before the job times out. When the job times out, the server will put the job back into the ready queue. Both the TTR and the actual time left can be found in response to the stats-job command.

A timeout value of 0 will cause the server to immediately return either a response or TIMED_OUT. A positive value of timeout will limit the amount of time the client will block on the reserve request until a job becomes available.

Beanstalk\Pool::setStream($class)
Description:

Sets the stream class to use for the connections in the pool

Parameters:
  • $class (string) – Name of stream class
Returns:

self

Beanstalk\Pool::setTimeout($timeout)
Description:

Set the connection timeout for attempting to connect to servers in the pool

Parameters:
  • $timeout (float) – Connection timeout in milliseconds
Returns:

self

Beanstalk\Pool::stats()
Description:The stats command gives statistical information about the system as a whole
Beanstalk\Pool::useTube($tube)
Description:

Use command

Parameters:
  • $tube (string) – The tube to use. If the tube does not exist, it will be created.
Returns:

self

The “use” command is for producers. Subsequent put commands will put jobs into the tube specified by this command. If no use command has been issued, jobs will be put into the tube named “default”.

Beanstalk\Pool::watchTube($tube)
Description:

Watch command

Parameters:
  • $tube (string) – Tube to add to the watch list. If the tube doesn’t exist, it will be created
Returns:

self

The “watch” command adds the named tube to the watch list for the connection pool. A reserve command will take a job from any of the tubes in the watch list. For each new connection, the watch list initially consists of one tube, named “default”.

Previous topic

Beanstalk\Job Class Ref

Next topic

Beanstalk\Stats Class Ref

This Page