Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/composer.lock
/vendor/
/protocol.txt
/.php_cs.cache
/.php-cs-fixer.cache
/.phpunit.result.cache
6 changes: 3 additions & 3 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config)
->setRiskyAllowed(true)
->setRules([
"@PSR1" => true,
Expand All @@ -13,7 +13,7 @@
"cast_spaces" => true,
"combine_consecutive_unsets" => true,
"function_to_constant" => true,
"no_multiline_whitespace_before_semicolons" => true,
"multiline_whitespace_before_semicolons" => true,
"no_unused_imports" => true,
"no_useless_else" => true,
"no_useless_return" => true,
Expand All @@ -27,7 +27,7 @@
"php_unit_fqcn_annotation" => true,
"phpdoc_summary" => true,
"phpdoc_types" => true,
"psr4" => true,
"psr_autoloading" => true,
"return_type_declaration" => ["space_before" => "none"],
"short_scalar_cast" => true,
"single_blank_line_before_namespace" => true,
Expand Down
23 changes: 15 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,27 @@
"Amp\\Beanstalk\\": "src"
}
},
"require": {
"amphp/amp": "^2",
"amphp/socket": "^1.0",
"autoload-dev": {
"psr-4": {
"Amp\\Beanstalk\\Test\\": "test"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"amphp/amp": "^3",
"amphp/socket": "^2",
"amphp/uri": "^0.1",
"symfony/yaml": "^3.3|^4|^5"
"symfony/yaml": "^3.3|^4|^5|^6"
},
"require-dev": {
"amphp/phpunit-util": "^1",
"phpunit/phpunit": "^6",
"friendsofphp/php-cs-fixer": "^2.3"
"amphp/phpunit-util": "^3",
"phpunit/phpunit": "^9",
"friendsofphp/php-cs-fixer": "^3"
},
"config": {
"platform": {
"php": "7.1.0"
"php": "8.1.0"
}
}
}
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");
// can connect to the server with an additional tube query parameter.
// $beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300?tube=foobar");

$systemStats = yield $beanstalk->getSystemStats();
$systemStats = $beanstalk->getSystemStats();

$readyJobs = $systemStats->currentJobsReady;
```
Expand Down
20 changes: 10 additions & 10 deletions docs/jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $payload = json_encode([
"path" => "/path/to/image.png"
]);

$jobId = yield $beanstalk->put($payload);
$jobId = $beanstalk->put($payload);
```

## Pulling Jobs off a Queue
Expand All @@ -30,16 +30,16 @@ $beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$beanstalk->watch('foobar');

while([$jobId, $jobData] = yield $beanstalk->reserve()) {
while([$jobId, $jobData] = $beanstalk->reserve()) {
// Work the job using $jobData
// Once you're finished, delete the job
yield $beanstalk->delete($jobId);
$beanstalk->delete($jobId);

// If there was an error, you can bury the job for inspection later
yield $beanstalk->bury($jobId);
$beanstalk->bury($jobId);

// Of you can release the job, to be picked up by a new worker
yield $beanstalk->release($jobId);
$beanstalk->release($jobId);
}
```

Expand All @@ -50,10 +50,10 @@ $beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$beanstalk->watch('foobar');

while([$jobId, $jobData] = yield $beanstalk->reserve()) {
while([$jobId, $jobData] = $beanstalk->reserve()) {
// Work the job
// If you still need time to work the job, you can utilize the touch command
yield $beantstalk->touch($jobId);
$beantstalk->touch($jobId);
}
```

Expand All @@ -62,6 +62,6 @@ while([$jobId, $jobData] = yield $beanstalk->reserve()) {
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$jobStats = yield $beanstalk->getJobStats($jobId = 42);
$jobStats = $beanstalk->getJobStats($jobId = 42);
$jobStats->state; // ready
```
2 changes: 1 addition & 1 deletion docs/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To see what stats are available for the system, checkout the [System](classes/sy
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$stats = yield $beanstalk->getSystemStats();
$stats = $beanstalk->getSystemStats();
```

## Close the Connection
Expand Down
24 changes: 12 additions & 12 deletions docs/tubes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ By default Beanstalk will use the default tube for reserving and storing new job
$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([
$jobId = $beanstalk->put($payload = json_encode([
"job" => bin2hex(random_bytes(16)),
"type" => "compress-image"
"path" => "/path/to/image.png"
Expand All @@ -23,7 +23,7 @@ $jobId = yield $beanstalk->put($payload = json_encode([
$beanstalk->use('foobar');

// This will store the job on the "foobar" tube.
$jobId = yield $beanstalk->put($payload = json_encode([
$jobId = $beanstalk->put($payload = json_encode([
"job" => bin2hex(random_bytes(16)),
"type" => "compress-image"
"path" => "/path/to/image.png"
Expand All @@ -37,7 +37,7 @@ If you need to pause a tube, preventing any new jobs from being reserved, you ca
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

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

## Watching and Ignoring Tubes
Expand All @@ -47,9 +47,9 @@ By default when you reserve a job you'll either pull from the `default` tube, or
```php
$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');
$beanstalk->watch($tube = 'foobar');
$beanstalk->watch($tube = 'barbaz');
$beanstalk->ignore($tube = 'default');
// Watchlist will contain "foobar" and "barbaz"
```

Expand All @@ -60,9 +60,9 @@ To find out which tubes your connection is currently watching.
```php
$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');
$beanstalk->watch($tube = 'foobar');
$beanstalk->watch($tube = 'barbaz');
$beanstalk->ignore($tube = 'default');

$watchlist = $beanstalk->listWatchedTubes();
```
Expand All @@ -74,7 +74,7 @@ If you need to see a list of all the tubes that exist on the server.
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

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

## Get the Tube Being Used
Expand All @@ -84,7 +84,7 @@ To determine which tube your client is currently using.
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

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

## Get Tube Stats
Expand All @@ -94,5 +94,5 @@ To see what stats are available for a tube, checkout the [Tube](classes/tube) cl
```php
$beanstalk = new Amp\Beanstalk\BeanstalkClient("tcp://127.0.0.1:11300");

$stats = yield $beanstalk->getTubeStats($tube = 'default');
$stats = $beanstalk->getTubeStats($tube = 'default');
```
14 changes: 7 additions & 7 deletions examples/consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
require __DIR__ . '/../vendor/autoload.php';

use Amp\Beanstalk\BeanstalkClient;
use Amp\Loop;
$beanstalk = new BeanstalkClient("tcp://127.0.0.1:11300");
try {
$beanstalk->watch('foobar');

Loop::run(function () {
$beanstalk = new BeanstalkClient("tcp://127.0.0.1:11300");
yield $beanstalk->watch('foobar');

while (list($jobId, $payload) = yield $beanstalk->reserve()) {
while (list($jobId, $payload) = $beanstalk->reserve()) {
echo "Job id: $jobId\n";
echo "Payload: $payload\n";

$beanstalk->delete($jobId);
}
});
} finally {
$beanstalk->quit();
}
14 changes: 6 additions & 8 deletions examples/producer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
require __DIR__ . '/../vendor/autoload.php';

use Amp\Beanstalk\BeanstalkClient;
use Amp\Loop;

Loop::run(function () {
$beanstalk = new BeanstalkClient("tcp://127.0.0.1:11300");
yield $beanstalk->use('foobar');
$beanstalk = new BeanstalkClient("tcp://127.0.0.1:11300");
try {
$beanstalk->use('foobar');

$payload = json_encode([
"job" => bin2hex(random_bytes(16)),
"type" => "compress-image",
"path" => "/path/to/image.png"
]);

$jobId = yield $beanstalk->put($payload);
$jobId = $beanstalk->put($payload);

echo "Inserted job id: $jobId\n";

} finally {
$beanstalk->quit();
});
}
19 changes: 8 additions & 11 deletions examples/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
require __DIR__ . '/../vendor/autoload.php';

use Amp\Beanstalk\BeanstalkClient;
use Amp\Beanstalk\Stats\System;
use Amp\Loop;

Loop::run(function () {
$beanstalk = new BeanstalkClient("tcp://127.0.0.1:11300");

/**
* @var System $systemStats
*/
$systemStats = yield $beanstalk->getSystemStats();
$beanstalk = new BeanstalkClient("tcp://127.0.0.1:11300");
try {
$systemStats = $beanstalk->getSystemStats();
echo "Active connections: {$systemStats->currentConnections}\n";
echo "Jobs ready: {$systemStats->currentJobsReady}\n";

} catch (\Throwable $t) {
echo $t::class . PHP_EOL;
} finally {
echo "Quit\n";
$beanstalk->quit();
});
}
Loading