PHPackages                             machobearstudio/simpleue - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. machobearstudio/simpleue

ActiveLibrary[Queues &amp; Workers](/categories/queues)

machobearstudio/simpleue
========================

Php package to manage queue tasks in a simple way

0262PHP

Since Jan 29Pushed 3y agoCompare

[ Source](https://github.com/machobearstudio/simpleue)[ Packagist](https://packagist.org/packages/machobearstudio/simpleue)[ RSS](/packages/machobearstudio-simpleue/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Simpleue - Simple Queue Worker for PHP
======================================

[](#simpleue---simple-queue-worker-for-php)

[![Build Status](https://camo.githubusercontent.com/6d63516bd4573bfafa75476e43f96f78fac3f3e2f7d5cf8cdec1d37d59131430/68747470733a2f2f7472617669732d63692e6f72672f6a617669627261766f2f73696d706c6575652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/javibravo/simpleue)[![Total Downloads](https://camo.githubusercontent.com/3d6bdb55cd78a821b830c5021bfb6028f400373e1fbba202706e214be7dfb853/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a617669627261766f2f73696d706c6575652e737667)](https://packagist.org/packages/javibravo/simpleue)[![Latest Stable Version](https://camo.githubusercontent.com/bb4f9224c2dc58d63c1eb664c155920938c2b7877fbc705e60703e3d82f7efdd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a617669627261766f2f73696d706c6575652e737667)](https://packagist.org/packages/javibravo/simpleue)

Simpleue provide a very simple way to run workers to consume queues (consumers) in PHP. The library have been developed to be easily extended to work with different queue servers and open to manage any kind of job.

Current implementations:

- **Redis** queue adapter.
- **AWS SQS** queue adapter.
- **Beanstalkd** queue adapter.

You can find an example of use in [simpleue-example](https://github.com/javibravo/simpleue-example)

Worker
------

[](#worker)

The lib has a worker class that run and infinite loop (can be stopped with some conditions) and manage all the stages to process jobs:

- Get next job.
- Execute job.
- job success then do ...
- job failed then do ...
- Execution error then do ...
- No jobs then do ...

The loop can be **stopped** under control using the following methods:

- **STOP Job** : The job handler allow to define a STOP job.
- **Max iterations** : It can be specified when the object is declared.

Each worker has one queue source and manage one type of jobs. Many workers can be working concurrently using the same queue source.

### Graceful Exit

[](#graceful-exit)

The worker is also capable for handling some posix signals, *viz.* `SIGINT` and `SIGTERM` so that it exits gracefully (waits for the current queue job to complete) when someone tries to manually stop it (usually with a `C-c` keystroke in a shell).

This behaviour is disabled by default. To enable it, you need to pass an extra parameter in the constructor of the worker class. See Usage below for an example.

**Note: This feature is not tested in HHVM, thus might not work as expected if you are running it on HHVM**

Queue
-----

[](#queue)

The lib provide an interface which allow to implement a queue connection for different queue servers. Currently the lib provide following implementations:

- **Redis** queue adapter.
- **AWS SQS** queue adapter.
- **Beanstalkd** queue adapter.

The queue interface manage all related with the queue system and abstract the job about that.

It require the queue system client:

- Redis : Predis\\Client
- AWS SQS : Aws\\Sqs\\SqsClient
- Beanstalkd : Pheanstalk\\Pheanstalk;

And was well the source *queue name*. The consumer will need additional queues to manage the process:

- **Processing queue** (only for Redis): It will store the item popped from source queue while it is being processed.
- **Failed queue**: All Jobs that fail (according the Job definition) will be add in this queue.
- **Error queue**: All Jobs that throw and exception in the management process will be add to this queue.

**Important**

For AWS SQS Queue all the queues must exist before start working.

Jobs
----

[](#jobs)

The job interface is used to manage the job received in the queue. It must manage the domain business logic and **define the STOP job**.

The job is abstracted form the queue system, so the same job definition is able to work with different queues interfaces. The job always receive the message body from the queue.

If you have different job types ( send mail, crop images, etc. ) and you use one queue, you can define **isMyJob**. If job is not expected type, you can send back job to queue.

Install
-------

[](#install)

Require the package in your composer json file:

```
{

    "require": {
        "javibravo/simpleue" : "dev-master",
    },

}
```

Usage
-----

[](#usage)

The first step is to define and implement the **Job** to be managed.

```
