https://github.com/tomahawkphp/queue
Tomahawk Worker Queue
https://github.com/tomahawkphp/queue
php tomahawk-queue worker-queue
Last synced: 2 months ago
JSON representation
Tomahawk Worker Queue
- Host: GitHub
- URL: https://github.com/tomahawkphp/queue
- Owner: tomahawkphp
- Created: 2017-01-27T13:11:34.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-09T19:12:33.000Z (almost 9 years ago)
- Last Synced: 2025-08-16T03:47:48.236Z (6 months ago)
- Topics: php, tomahawk-queue, worker-queue
- Language: PHP
- Size: 59.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
Awesome Lists containing this project
README
# Tomahawk Queue
A nice and simple PHP Worker Queue library
## Requirements
- PHP 7.0 +
- pcntl extension.
- posix extension.
## Installation
You can install Tomahawk Queue using composer:
`composer require tomahawk/queue`
### 1. Setup configuration
First you need to create a new file called `tomahawk.xml`
You will need to configure the following things:
- Storage directory - for logs and pid files
- Bootstrap file (optional) - Allows you to add event listeners and extend storage
- Your workers
Below is an example:
```xml
```
### 2. Create Bootstrap file
Bootstrap example file
```php
'tcp',
'host' => '10.0.0.1',
'port' => 6379,
]);
return new RedisStorage($client);
};
$eventDispatcher = $container[EventDispatcherInterface::class];
// Add events
$eventDispatcher->addListener(\Tomahawk\Queue\JobEvents::PROCESSED, function(\Tomahawk\Queue\Event\PreProcessEvent $event) {
// Log to a file
});
$container[EventDispatcherInterface::class];
```
## Using the CLI
### Create a new worker
```./bin/tomahawk-queue work emails emails --daemon```
### Queue a new job to worker
```./bin/tomahawk-queue queue emails JobClass {"id":"1"}```
### List running workers
```./bin/tomahawk-queue list```
### Stop a running worker
```./bin/tomahawk-queue stop emails```
### Load and run all workers defined in configuration file
```./bin/tomahawk-queue load```
## Using the Queue Manager
If you have your works setup on a different VM or server you can still push jobs onto the queue using the Queue Manager.
Below is an example of how to do this
```php
'tcp',
'host' => '10.0.0.1',
'port' => 6379,
]);
$storage = new RedisStorage($client);
$manager = new Manager($storage);
$arguments = [
'email' => '...',
'subject' => '...',
];
$manager->queue('queue_email', 'JobClass', $arguments);
```
## License
Tomahawk Queue is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)