zlikavac32 / beanstalkd-lib-bundle
Bundle for zlikavac32/beanstalkd-lib
Requires
- php: ^7.4
- ext-pcntl: *
- ext-posix: *
- php-ds/php-ds: ^1.2
- symfony/config: ^4.2
- symfony/console: ^4.1
- symfony/dependency-injection: ^4.1
- symfony/http-kernel: ^3.4 || ^4.0
- symfony/var-dumper: ^4.0
- ulrichsg/getopt-php: ^3.3
- zlikavac32/beanstalkd-lib: ^0.5.0
- zlikavac32/nsb-decorators: ^0.1.0
- zlikavac32/php-enum: ^3.0
- zlikavac32/symfony-extras: ^0.2.0
Requires (Dev)
- phpspec/phpspec: ^6.1
- phpunit/phpunit: ^8.5
Suggests
- ext-ds: For better performance with php-ds
README
Bundle for zlikavac32/beanstalkd-lib
Table of contents
Installation
Recommended installation is through Composer.
composer require zlikavac32/beanstalkd-lib-bundle
Bundle must be enabled in config/bundles.php
.
return [ /* ... */ Zlikavac32\BeanstalkdLibBundle\BeanstalkdLibBundle::class => ['all' => true], /* ... */ ]
Next add default configuration entry for beanstalkd_lib
. For example, in config/services/beanstalkd_lib.yaml
. Check Configuration section for more info.
beanstalkd_lib: ~
This library uses zlikavac32/nsb-decorators which requires custom autoloader in application entry points like bin/console
.
use Zlikavac32\NSBDecorators\Proxy; /* ... */ spl_autoload_register(Proxy::class.'::loadFQN');
For now, since proxied decorators are evaluated, container requires must not be inlined (container.dumper.inline_class_loader
parameter must not exist or be set to false
).
Async signals are also a requirement.
pcntl_async_signals(true);
Configuration
Default configuration looks like:
beanstalkd_lib: adapters: socket: Zlikavac32\BeanstalkdLib\Adapter\PHP\Socket\NativePHPSocket yaml_parser: Zlikavac32\BeanstalkdLib\Adapter\Symfony\Yaml\SymfonyYamlParser server: host: 127.0.0.1 port: 11300
Custom adapters can be implemented for better integration with existing software.
Usage
This section explains how to use this bundle.
Tube definition
To use beanstalkd lib client, every managed tube must be configured.
tube.domain_tube: # keys value itself is not important to the bundle class: Zlikavac32\BeanstalkdLib\Client\TubeConfiguration\StaticTubeConfiguration arguments: $defaultDelay: 0 $defaultPriority: 1024 $defaultTimeToRun: 60 $defaultTubePauseDelay: 86400 $serializer: '@DomainSerializer' tags: - { name: tube_configuration, tube: brute_force_hash }
Tag tube_configuration
collects tube configurations and links them with the client.
Optionally, one could also use linker
tag to link with the serializer, as can be seen in the examples/full/container.yaml.
Runner definition
To define tube runner, we can use job_runner
tag. This tag collects runners and links them with the job dispatcher.
Foo\Runner\SomeRunnerClass: tags: - { name: job_runner, tube: tube_for_this_runner }
Additional decorators can be applied either manually or through decorator
tag, as can be seen in the examples/full/container.yaml.
To run existing runners, use bin/console worker:run
.
Server controller
Simple REPL controller for the client is provided as bin/console worker:controller
. It can be used also to run standalone commands.
Features include:
- list tubes
- pause/unpause tubes
- print stats (with optional refresh)
- flush tube/tubes
To use pager in peek
command, evironment variable PAGER
must be set to a pager program. less
is one such program whcih can be used directly like PAGER=less bin/console ...
or exported somewhere.
For less
, additional environment variable LESS
that describes less
arguments can be defined. For example, LESS='-F' PAGER=less bin/console
can be used to skip paging if the whole text can be displayed on screen.
In Docker, -R
should be used to display color escape sequences correctly.
Examples
You can see more examples with code comments in examples.