Beanstalk\Connection Class Ref

class Beanstalk\Connection
Description:Beanstalkd connection
Author:Joshua Dechant <jdechant@shapeup.com>

Class Methods

Beanstalk\Connection::__construct($address, $stream[, $timeout = 500])
Description:

Constructor; establishes connection stream

Parameters:
  • $address (string) – Beanstalkd server address in the format “host:port”
  • $stream (BeanstalkConnectionStream) – Stream to use for connection
  • $timeout (float) – Connection timeout in milliseconds
Throws:

BeanstalkException When a connection cannot be established

Beanstalk\Connection::bury($id, $priority)
Description:

Bury command

Parameters:
  • $id (integer) – The job id to bury
  • $priority (integer) – A new priority to assign to the job

The bury command puts a job into the “buried” state. Buried jobs are put into a FIFO linked list and will not be touched by the server again until a client kicks them with the “kick” command.

Beanstalk\Connection::close()
Description:Close the connection
Beanstalk\Connection::connect()
Description:Connect to the beanstalkd server
Returns:boolean
Throws:BeanstalkException When a connection cannot be established
Beanstalk\Connection::delete($id)
Description:

Delete command

Parameters:
  • $id (integer) – The job id to delete
Returns:

boolean

Throws:

BeanstalkException

The delete command removes a job from the server entirely. It is normally used by the client when the job has successfully run to completion. A client can delete jobs that it has reserved, ready jobs, and jobs that are buried.

Beanstalk\Connection::getServer()
Description:Get the Beanstalkd server address
Returns:string Beanstalkd server address in the format “host:port”
Beanstalk\Connection::getStream()
Description:Get the connect’s stream
Returns:BeanstalkConnectionStream
Beanstalk\Connection::getTimeout()
Description:Get the connection timeout
Returns:float Connection timeout
Beanstalk\Connection::ignoreTube($tube)
Description:

Ignore command

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

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

Beanstalk\Connection::isTimedOut()
Description:Has the connection timed out?
Returns:boolean
Beanstalk\Connection::kick($bound)
Description:

Kick command

Parameters:
  • $bound (integer) – Upper bound on the number of jobs to kick. The 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\Connection::listTubes()
Description:The list-tubes command returns a list of all existing tubes
Beanstalk\Connection::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\Connection::peek($id)
Description:

Return job $id

Parameters:
  • $id (integer) – Id of job to return
Returns:

BeanstalkJob

Throws:

BeanstalkException When job cannot be found

Beanstalk\Connection::peekBuried()
Description:Return the next job in the list of buried jobs
Returns:BeanstalkJob
Throws:BeanstalkException When no jobs in buried state
Beanstalk\Connection::peekDelayed()
Description:Return the delayed job with the shortest delay left
Returns:BeanstalkJob
Throws:BeanstalkException When no jobs in delayed state
Beanstalk\Connection::peekReady()
Description:Return the next ready job
Returns:BeanstalkJob
Throws:BeanstalkException When no jobs in ready state
Beanstalk\Connection::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\Connection::release($id, $priority, $delay)
Description:

Release command

Parameters:
  • $id (integer) – The job id to release
  • $priority (integer) – A new priority to assign to the job
  • $delay (integer) – Number of seconds to wait before putting the job in the ready queue. The job will be in the “delayed” state during this time

The release command puts a reserved job back into the ready queue (and marks its state as “ready”) to be run by any client. It is normally used when the job fails because of a transitory error.

Beanstalk\Connection::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\Connection::setTimeout($timeout)
Description:

Set the connection timeout

Parameters:
  • $timeout (float) – Connection timeout in milliseconds
Beanstalk\Connection::stats()
Description:The stats command gives statistical information about the system as a whole.
Beanstalk\Connection::statsJob($id)
Description:

The stats-job command gives statistical information about the specified job if it exists.

Parameters:
  • $id (integer) – The job id to get stats on
Returns:

BeanstalkStats

Throws:

BeanstalkException When the job does not exist

Beanstalk\Connection::statsTube($tube)
Description:

The stats-tube command gives statistical information about the specified tube if it exists.

Parameters:
  • $tube (string) – is a name at most 200 bytes. Stats will be returned for this tube.
Returns:

BeanstalkStats

Throws:

BeanstalkException When the tube does not exist

Beanstalk\Connection::touch($id)
Description:

Touch command

Parameters:
  • $id (integer) – The job id to touch
Returns:

boolean

Throws:

BeanstalkException

The “touch” command allows a worker to request more time to work on a job. This is useful for jobs that potentially take a long time, but you still want the benefits of a TTR pulling a job away from an unresponsive worker. A worker may periodically tell the server that it’s still alive and processing a job (e.g. it may do this on DEADLINE_SOON).

Beanstalk\Connection::useTube($tube)
Description:

Use command

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

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\Connection::validateResponse($response)
Description:

Generic validation for all responses from beanstalkd

Parameters:
  • $response (string) –
Returns:

boolean true when response is valid

Throws:

BeanstalkException When response is invalid

Beanstalk\Connection::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

The “watch” command adds the named tube to the watch list for the current connection. 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”.