Documentation Packages Getting Started FAQ Support

Beanstalk ⋅ Working with Tubes

Using a Different Tube

By default Beanstalk will use the default tube for reserving and storing new jobs. To work with a different tube, you can use use:

$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

// This will store the job on the "default" tube.
$jobId = yield $beanstalk->put($payload = json_encode([
    "job" => bin2hex(random_bytes(16)),
    "type" => "compress-image"
    "path" => "/path/to/image.png"
]););

$beanstalk->use('foobar');

// This will store the job on the "foobar" tube.
$jobId = yield $beanstalk->put($payload = json_encode([
    "job" => bin2hex(random_bytes(16)),
    "type" => "compress-image"
    "path" => "/path/to/image.png"
]));

Pausing a Tube

If you need to pause a tube, preventing any new jobs from being reserved, you can do the following:

$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

yield $beanstalk->pause($tube = 'foobar');

Watching and Ignoring Tubes

By default when you reserve a job you’ll either pull from the default tube, or the tube you useed. If you’d like to reserve jobs from other tubes, you can use watch to pull from multiple tubes. If you need to remove a job from the watch list, you can use ignore.

$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

yield $beanstalk->watch($tube = 'foobar');
yield $beanstalk->watch($tube = 'barbaz');
yield $beanstalk->ignore($tube = 'default');
// Watchlist will contain "foobar" and "barbaz"

Getting the Watched Tubes

To find out which tubes your connection is currently watching.

$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

yield $beanstalk->watch($tube = 'foobar');
yield $beanstalk->watch($tube = 'barbaz');
yield $beanstalk->ignore($tube = 'default');

$watchlist = $beanstalk->listWatchedTubes();

Get a List of All Existing Tubes

If you need to see a list of all the tubes that exist on the server.

$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$tubes = yield $beanstalk->listTubes();

Get the Tube Being Used

To determine which tube your client is currently using.

$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$tube = yield $beanstalk->getUsedTube();

Get Tube Stats

To see what stats are available for a tube, checkout the Tube class page.

$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$stats = yield $beanstalk->getTubeStats($tube = 'default');