PHPackages                             herroffizier/yiiq - 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. herroffizier/yiiq

ActiveLibrary

herroffizier/yiiq
=================

Background job manager for Yii

42.0k[2 PRs](https://github.com/herroffizier/yiiq/pulls)PHP

Since Dec 15Pushed 9y ago4 watchersCompare

[ Source](https://github.com/herroffizier/yiiq)[ Packagist](https://packagist.org/packages/herroffizier/yiiq)[ RSS](/packages/herroffizier-yiiq/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Yiiq
====

[](#yiiq)

[![Build Status](https://camo.githubusercontent.com/2224dee11db99a1deb8bd027bb23a24ad4f27c7e27fe0b1980fd9ca2a82e619e/68747470733a2f2f7472617669732d63692e6f72672f686572726f6666697a6965722f796969712e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/herroffizier/yiiq) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/71b324116afa2c74fa4d1e95c6818ee71fcfe6cc5cffdd66266d95746ecdec09/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f686572726f6666697a6965722f796969712f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/herroffizier/yiiq/?branch=master) [![Code Coverage](https://camo.githubusercontent.com/8df6eacd7ee3f5e7866ea7ceab7e7d181700248bafc79a7f3c0fa5b511e0d1ee/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f686572726f6666697a6965722f796969712f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/herroffizier/yiiq/?branch=master) [![Code Climate](https://camo.githubusercontent.com/17a4b88e7fc1493864bc74df85581fdf5e9d377507fd04066a548aa7cbfe0be8/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f686572726f6666697a6965722f796969712f6261646765732f6770612e737667)](https://codeclimate.com/github/herroffizier/yiiq)

**Yiiq** is a powerful [Redis](http://redis.io/)-backed multithreaded background job manager for Yii Framework designed with stability and simplicity in mind.

To run a job just wrap it in class and type:

```
Yii::app()->yiiq->enqueue('\MyJob');
```

And it's done!

Table of contents
-----------------

[](#table-of-contents)

- [Features](#user-content-features)
- [Requirements](#user-content-requirements)
- [Installation](#user-content-installation)
- [Usage](#user-content-usage)
    - [Creating jobs](#user-content-creating-jobs)
        - [Simple job](#user-content-simple-job)
        - [Scheduled job](#user-content-scheduled-job)
        - [Repeatable job](#user-content-repeatable-job)

Features
--------

[](#features)

- **Stability**
    If job crashed, daemon stays alive. If server crashed, daemon recovers its state with all unfinished jobs.
- **Multithreading**
    You can run as many processes as you need.
- **Queueing**
    Jobs may be grouped in different queues which handled by different processes.
- **Clarity**
    You can track your job status at every point of time.
- **Scheduling**
    Jobs may be executed at certain time or immediately. Once or many times.
- **Feedback**
    Jobs may return result back to the extension.

Requirements
------------

[](#requirements)

- Unix platform
- PHP &gt;= 5.4
- Redis
- pcntl extension
- Yii Framework &gt;= 1.1.14
- [YiiRedis](https://github.com/phpnode/YiiRedis)

Installation
------------

[](#installation)

Following steps are described assuming the fact that you have default Yii application layout, which contains two config files: `main.php` and `console.php` for web and console applications accordingly. **Yiiq** consists of two main parts too: framework extension and daemon. Extension queues jobs and daemon executes them. In view of the fact that daemon acts as console application, it will use `console.php` config file, whilst extension will use both files depending on application type in which it's being used. So pay attention to the fact that **Yiiq** and **YiiRedis** extensions must be included in both files.

At first, install **Yiiq** via Composer:

```
composer require herroffizier/yiiq:dev-master

```

At this point make sure that `vendor/autoload.php` is included in both config files.

Now we need to set up extension. Add it to your `components` array (must be added in both files also):

```
'components' => array(

    // ...

    'yiiq' => array(
        'class' => '\Yiiq\Yiiq',
        // Name to identify daemon in process list (optional)
        'name' => 'Yiiq test instance',
    ),

    // ...

),
```

Note, that **YiiRedis** extension must be loaded in both files too!

Finally, add following commands to `commandMap` in `console.php`:

```
'commandMap' => array(

    // ...

    // Control Yiiq command
    'yiiq' => array(
        'class' => '\Yiiq\commands\Main',
    ),

    // Daemon Yiiq command
    'yiiqWorker' => array(
        'class' => '\Yiiq\commands\Worker',
    ),

    // ...

),
```

Now it's time to run daemon. Remember, daemon is responsible for job executing, therefore it must be runnign all the time. Type following command in `protected` folder of your application.

```
./yiic yiiq start --log=yiiq.log

```

`log` parameter is optional but it highly recommended for first run at least.

Run `./yiic yiiq status` to check if daemon started correctly. You should see something like this:

```
All processes (28235) are alive. Everything looks good.

```

If daemon is not running refer to `application.log` and `yiiq.log` (both stored in `runtime` folder) for details.

Usage
-----

[](#usage)

### Creating jobs

[](#creating-jobs)

To create a job you should extend `\Yiiq\jobs\Payload` class and implement it's `run()` method:

```
class YiiqDummyJob extends \Yiiq\jobs\Payload
{
    /**
     * Time to wait before exit.
     *
     * @var integer
     */
    public $sleep = 10;

    /**
     * This method should contain all the job logic.
     *
     * @return {mixed} all returned data will be saved in Redis
     *                 (for non-repeatable jobs)
     */
    public function run()
    {
        Yii::trace(
            'Started dummy job '.$this->queue.':'.$this->id
            .' (sleep for '.$this->sleep.'s).'
        );
        sleep($this->sleep);
        Yii::trace('Job '.$this->queue.':'.$this->id.' completed.');
    }

}
```

In fact there are three types of jobs in **Yiiq**: simple, scheduled and repeatable. First one executed immediately, second one will execute at certain time, and third one will run infinitely in accordance with specified interval.

#### Simple job

[](#simple-job)

To add a simple job you may use one of following calls. As you already know, this job will be executed as soon as possible and only once.

```
// Add YiiqDummyJob with default arguments to default queue.

// Via arguments:
$job = Yii::app()->yiiq->enqueue('\YiiqDummyJob');

// Via method chaining:
$job = Yii::app()->yiiq->
    create('\YiiqDummyJob')->
    enqueue();

// Add YiiqDummyJob with customized arguments to default queue.

// Via arguments:
$job = Yii::app()->yiiq->enqueue(
    '\YiiqDummyJob',
    ['sleep' => 5]
);

// Via method chaining:
$job = Yii::app()->yiiq->
    create('\YiiqDummyJob')->
    withArgs(['sleep' => 5])->
    enqueue();

// Add YiiqDummyJob with customized arguments to 'custom' queue.

// Via arguments:
$job = Yii::app()->yiiq->enqueue(
    '\YiiqDummyJob',
    ['sleep' => 5],
    'custom'
);

// Via method chaining:
$job = Yii::app()->yiiq->
    create('\YiiqDummyJob')->
    into('custom')->
    withArgs(['sleep' => 5])->
    enqueue();
```

#### Scheduled job

[](#scheduled-job)

To schedule a job at certain time, you must specify time or interval:

```
// Run job at certain time.

// Via arguments:
$job = Yii::app()->yiiq->enqueueAt(
    time() + 60,
    'YiiqDummyJob'
);

// Via method chaining:
$job = Yii::app()->yiiq->
    create('\YiiqDummyJob')->
    runAt(time() + 60)->
    enqueue();

// Run job after 60 seconds. In fact exactly the same as above.

// Via arguments:
$job = Yii::app()->yiiq->enqueueAfter(
    60,
    '\YiiqDummyJob'
);

// Via method chaining:
$job = Yii::app()->yiiq->
    create('\YiiqDummyJob')->
    runAt(time() + 60)->
    enqueue();
```

#### Repeatable job

[](#repeatable-job)

To create a repeatable job, you may use following code:

```
// Run job each 300 seconds.

// Via arguments:
$job = Yii::app()->yiiq->enqueueEach(
    300,
    '\YiiqDummyJob'
);

// Via method chaining:
$job = Yii::app()->yiiq->
    create('\YiiqDummyJob')->
    runEach(300)->
    enqueue();
```

Note that repeatable job cannot return any data back to **Yiiq**.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 99% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/820232d3f5de11b08332a98ca93b025ab46d7e3563ddaec2ce6d042828718983?d=identicon)[herroffizier](/maintainers/herroffizier)

---

Top Contributors

[![korotin](https://avatars.githubusercontent.com/u/277992?v=4)](https://github.com/korotin "korotin (97 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

### Embed Badge

![Health badge](/badges/herroffizier-yiiq/health.svg)

```
[![Health](https://phpackages.com/badges/herroffizier-yiiq/health.svg)](https://phpackages.com/packages/herroffizier-yiiq)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
