PHPackages                             giovanne-oliveira/php-resque - 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. [Caching](/categories/caching)
4. /
5. giovanne-oliveira/php-resque

ActiveLibrary[Caching](/categories/caching)

giovanne-oliveira/php-resque
============================

Redis backed library for creating background jobs and processing them later.

3.2.0(4mo ago)0404↓30.2%MITPHPPHP ^8.1|^8.2|^8.3|^8.4

Since Oct 9Pushed 4mo agoCompare

[ Source](https://github.com/giovanne-oliveira/php-resque)[ Packagist](https://packagist.org/packages/giovanne-oliveira/php-resque)[ Docs](https://github.com/mjphaynes/php-resque/)[ RSS](/packages/giovanne-oliveira-php-resque/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (7)Versions (22)Used By (0)

php-resque
==========

[](#php-resque)

php-resque (pronounced like "rescue") is a Redis-backed library for creating background jobs, placing those jobs on multiple queues, and processing them later.

---

#### Contents

[](#contents)

- [Background](#background)
- [Requirements](#requirements)
- [Getting Started](#getting-started)
- [Jobs](#jobs)
    - [Defining Jobs](#defining-jobs)
    - [Queueing Jobs](#queueing-jobs)
    - [Delaying Jobs](#delaying-jobs)
    - [Job Statuses](#job-statuses)
- [Workers](#workers)
    - [Signals](#signals)
    - [Forking](#forking)
    - [Autoload Job Classes](#autoload-job-classes)
- [Commands &amp; Options](#commands--options)
- [Logging](#logging)
- [Event/Hook System](#eventhook-system)
- [Configuration Options](#configuration-options)
- [Redis](#redis)
- [Contributing](#contributing)
- [Contributors](#contributors)

---

Background
----------

[](#background)

This version of php-resque is based on the work originally done by [chrisboulton](https://github.com/chrisboulton/php-resque) where he ported the [ruby version](https://github.com/resque/resque) of the same name that was created by [GitHub](http://github.com/blog/542-introducing-resque).

The reasoning behind rewriting the previous work is to add better support for horizontal scaling of worker servers and to improve job failure tolerance to create a very highly available system. Integration with Monolog means that very verbose logging is achievable which makes it far easier to solve bugs across distributed systems. And an extensive events/hooks system enables deeper integration and stats gathering.

This version provides features such as:

- Workers can be distributed between multiple machines.
- Resilient to memory leaks (jobs are run on forked processes).
- Expects and logs failure.
- Logging uses Monolog.
- Ability to push Closures to queues.
- Job status and output tracking.
- Jobs will fail cleanly if out of memory or if maximum execution time is reached.
- Will mark a job as failed, if a forked child running a job does not exit with a status code of 0.
- Has a built-in event system to enable hooks for deep integration.
- Support for priorities (queues).

*This version is not a direct port of Github's Resque and therefore is not compatible with it, or their web interface.*A Resque web interface built with Symfony 3.x for this version can be found [on GitHub](https://github.com/xelan/resque-webui-bundle/).

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

[](#requirements)

You must have the following installed to run php-resque:

- [Redis](http://redis.io/)
- [PHP 7.2+](http://php.net/)
- [PCNTL PHP extension](http://php.net/manual/en/book.pcntl.php)
- [Composer](http://getcomposer.org/)

Optional:

- [Phpiredis](https://github.com/nrk/phpiredis)

---

Getting Started
---------------

[](#getting-started)

The easiest way to work with php-resque is when it's installed as a [Composer package](https://packagist.org/packages/mjphaynes/php-resque) inside your project.

Add php-resque to your application by running:

```
composer require mjphaynes/php-resque

```

If you haven't already, add the Composer autoloader to your project's bootstrap:

```
require 'vendor/autoload.php';
```

Jobs
----

[](#jobs)

### Defining Jobs

[](#defining-jobs)

Each job should be in its class, and php-resque has a blueprint for building them.

```
use Resque\Blueprint\Job as JobBlueprint;
use Resque\Job;

class MyJob extends JobBlueprint
{
    /**
     * Runs any required logic before the job is performed.
     *
     * @param Job $job Current job instance
     */
    public function setUp(Job $job): void
    {
    }

    /**
     * Actual job logic.
     *
     * @param array $args Arguments passed to the job
     * @param Job   $job  Current job instance
     */
    public function perform(array $args, Job $job): void
    {
        // Do some work
    }

    /**
     * Runs after the job is performed.
     *
     * @param Job $job Current job instance
     */
    public function tearDown(Job $job): void
    {
    }
}
```

When the job is run, the class will be instantiated and any arguments will be sent as arguments to the perform method. The current job instance (`Resque\Job`) is passed to the perform method as the second argument.

Any exception thrown by a job will result in the job failing - be careful here and make sure you handle the exceptions that shouldn't result in a job failing. If you want to cancel a job (instead of having it fail) then you can throw a `Resque\Exception\Cancel`exception and the job will be marked as canceled.

Jobs can also have `setUp` and `tearDown` methods. If a `setUp` method is defined, it will be called before the perform method is run. The `tearDown` method if defined, will be called after the job finishes. If an exception is thrown in the `setUp` method the perform method will not be run. This is useful for cases where you have different jobs that require the same bootstrap, for instance, a database connection.

### Queueing Jobs

[](#queueing-jobs)

To add a new job to the queue use the `Resque::push` method.

```
$job = Resque::push(MyJob::class, ['arg1' => true, 'arg2']);
```

The first argument is the fully resolved classname for your job class (if you're wondering how php-resque knows about your job classes see [autoloading job classes](#autoload-job-classes)). The second argument is an array of any arguments you want to pass through to the job class.

It is also possible to push a Closure onto the queue. This is very convenient for quick, simple tasks that need to be queued. When pushing Closures onto the queue, the `__DIR__`and `__FILE__` constants should not be used.

```
$job = Resque::push(function ($job) {
    echo "This is a inline job {$job->getId()}!";
});
```

It is possible to push a job onto another queue (the default queue is called `default`) by passing through a third parameter to the `Resque::push` method which contains the queue name.

```
$job = Resque::push(SendEmail::class, [], 'email');
```

### Delaying Jobs

[](#delaying-jobs)

It is possible to schedule a job to run at a specified time in the future using the `Resque::later`method. You can do this by either passing through an `int` or a `DateTime` object.

```
$job = Resque::later(60, MyJob::class);
$job = Resque::later(1398643990, MyJob::class);
$job = Resque::later(new \DateTime('+2 mins'), MyJob::class);
$job = Resque::later(new \DateTime('2014-07-08 11:14:15'), MyJob::class);
```

If you pass through an integer and it is smaller than `94608000` seconds (3 years) php-resque will assume you want a time relative to the current time (I mean, who delays jobs for more than 3 years anyway??). Note that you must have a worker running at the specified time for the job to run.

### Job Statuses

[](#job-statuses)

php-resque tracks the status of a job. The status information will allow you to check if a job is in the queue, currently being run, failed, etc. To track the status of a job you must capture the job id of a pushed job.

```
$job = Resque::push(MyJob::class);
$jobId = $job->getId();
```

To fetch the status of a job:

```
$job = Job::load($jobId);
$status = $job->getStatus();
```

Job statuses are defined as constants in the Job class. Valid statuses are:

- `Job::STATUS_WAITING` - The job is still queued
- `Job::STATUS_DELAYED` - Job is delayed
- `Job::STATUS_RUNNING` - The job is currently running
- `Job::STATUS_COMPLETE` - Job is complete
- `Job::STATUS_CANCELLED` - The job has been canceled
- `Job::STATUS_FAILED` - Job has failed
- `false` - Failed to fetch the status - is the id valid?

Statuses are available for up to 7 days after a job has been completed or failed, and are then automatically expired. This timeout can be changed in the configuration file.

Workers
-------

[](#workers)

To start a worker navigate to your project root and run:

```
$ vendor/bin/resque worker:start

```

Note that once this worker has started, it will continue to run until it is manually stopped. You may use a process monitor such as [Supervisor](http://supervisord.org/) to run the worker as a background process and to ensure that the worker does not stop running.

If the worker is a background task you can stop, pause &amp; restart the worker with the following commands:

```
$ vendor/bin/resque worker:stop
$ vendor/bin/resque worker:pause
$ vendor/bin/resque worker:resume

```

The commands take inline configuration options as well as reading from a [configuration file](https://github.com/mjphaynes/php-resque/blob/master/docs/configuration.md#file).

For instance, to specify that the worker only processes jobs on the queues named `high` and `low`, as well as allowing a maximum of `30MB` of memory for the jobs, you can run the following:

```
$ vendor/bin/resque worker:start --queue=high,low --memory=30 -vvv

```

Note that this will check the `high` queue first and then the `low` queue, so it is possible to facilitate job queue priorities using this. To run all queues use `*` - this is the default value. The `-vvv` enables very verbose logging. To silence any logging the `-q` flag is used.

For more commands and the full list of options please see the [commands](https://github.com/mjphaynes/php-resque/blob/master/docs/commands.md) documentation.

In addition, if the workers are running on a different host, you may trigger a graceful shutdown of a worker remotely via the data in Redis. For example:

```
foreach(Worker::allWorkers() as $worker) {
    $worker->shutdown();
}
```

### Signals

[](#signals)

Signals work on supported platforms. Signals sent to workers will have the following effect:

- `QUIT` - Wait for the child to finish processing then exit
- `TERM` / `INT` - Immediately kill child then exit
- `USR1` - Immediately kill the child but don't exit
- `USR2` - Pause worker, no new jobs will be processed
- `CONT` - Resume worker

### Forking

[](#forking)

When php-resque runs a job it first forks the process to a child process. This is so that if the job fails the worker can detect that the job failed and will continue to run. The forked child will always exit as soon as the job finishes.

The PECL module () must be installed to use php-resque.

### Autoload Job Classes

[](#autoload-job-classes)

Getting your application underway also requires telling the worker about your job classes, using either an autoloader or including them. If you're using Composer then it will be relatively straightforward to add your job classes there.

Alternatively, you can do so in the `resque.yml` file or by setting the include argument:

```
$ vendor/bin/resque worker:start --include=/path/to/your/include/file.php

```

There is an example of how this all works in the `examples/` folder in this project.

Commands &amp; Options
----------------------

[](#commands--options)

For the full list of php-resque commands and their associated arguments, please see the [commands documentation](https://github.com/mjphaynes/php-resque/blob/master/docs/commands.md).

Logging
-------

[](#logging)

php-resque is integrated with [Monolog](https://github.com/Seldaek/monolog) which enables extensive logging abilities. For full documentation please see the [logging documentation](https://github.com/mjphaynes/php-resque/blob/master/docs/logging.md).

Event/Hook System
-----------------

[](#eventhook-system)

php-resque has an extensive events/hook system to allow developers deep integration with the library without having to modify any core files. For full documentation and a list of all events please see the [hooks documentation](https://github.com/mjphaynes/php-resque/blob/master/docs/hooks.md).

Configuration Options
---------------------

[](#configuration-options)

For a complete list of all configuration options, please see the [configuration documentation](https://github.com/mjphaynes/php-resque/blob/master/docs/configuration.md).

Redis
-----

[](#redis)

You can either set the Redis connection details inline or in the [configuration file](https://github.com/mjphaynes/php-resque/blob/master/docs/configuration.md). To set when running a command:

```
$ vendor/bin/resque [command] --host= --port=

```

Contributing
------------

[](#contributing)

PHP-Resque v4 is for PHP 7.2 or higher, new code must work with PHP 7.2. Please follow the [PSR-12 coding style](https://www.php-fig.org/psr/psr-12/) where possible. New features should come with tests.

---

Contributors
------------

[](#contributors)

Contributing to the project would be a massive help in maintaining and extending the script. If you're interested in contributing, issue a pull request on GitHub.

- [mjphaynes](https://github.com/mjphaynes)
- [chrisboulton](https://github.com/chrisboulton) (original port)
- [Project contributors](https://github.com/mjphaynes/php-resque/graphs/contributors)

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance78

Regular maintenance activity

Popularity16

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity90

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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.

###  Release Activity

Cadence

Every ~233 days

Recently: every ~601 days

Total

20

Last Release

120d ago

Major Versions

1.3.0 → 2.0.02017-02-28

2.2.2 → 3.1.12023-02-08

PHP version history (3 changes)1.0.0PHP &gt;=5.3.0

3.1.1PHP &gt;=7.1.0

3.2.0PHP ^8.1|^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/a064e3d831d62179312b283172daa65540e2c375525a7891d8faac7009ab1ca6?d=identicon)[giovanne-oliveira](/maintainers/giovanne-oliveira)

---

Top Contributors

[![xelan](https://avatars.githubusercontent.com/u/5080535?v=4)](https://github.com/xelan "xelan (54 commits)")[![PAXANDDOS](https://avatars.githubusercontent.com/u/40315177?v=4)](https://github.com/PAXANDDOS "PAXANDDOS (36 commits)")[![francislavoie](https://avatars.githubusercontent.com/u/2111701?v=4)](https://github.com/francislavoie "francislavoie (25 commits)")[![mjphaynes](https://avatars.githubusercontent.com/u/697891?v=4)](https://github.com/mjphaynes "mjphaynes (12 commits)")[![skors](https://avatars.githubusercontent.com/u/2559733?v=4)](https://github.com/skors "skors (11 commits)")[![MiRacLe-RPZ](https://avatars.githubusercontent.com/u/920542?v=4)](https://github.com/MiRacLe-RPZ "MiRacLe-RPZ (9 commits)")[![scones](https://avatars.githubusercontent.com/u/472339?v=4)](https://github.com/scones "scones (2 commits)")[![mplx](https://avatars.githubusercontent.com/u/1986588?v=4)](https://github.com/mplx "mplx (2 commits)")[![emarref](https://avatars.githubusercontent.com/u/556594?v=4)](https://github.com/emarref "emarref (2 commits)")[![murali565](https://avatars.githubusercontent.com/u/55405110?v=4)](https://github.com/murali565 "murali565 (2 commits)")[![mrcroy](https://avatars.githubusercontent.com/u/1017152?v=4)](https://github.com/mrcroy "mrcroy (1 commits)")[![gemblue](https://avatars.githubusercontent.com/u/879313?v=4)](https://github.com/gemblue "gemblue (1 commits)")[![giovanne-oliveira](https://avatars.githubusercontent.com/u/5747295?v=4)](https://github.com/giovanne-oliveira "giovanne-oliveira (1 commits)")[![davidtall](https://avatars.githubusercontent.com/u/9320941?v=4)](https://github.com/davidtall "davidtall (1 commits)")[![oanhnn](https://avatars.githubusercontent.com/u/1757120?v=4)](https://github.com/oanhnn "oanhnn (1 commits)")[![scotwells](https://avatars.githubusercontent.com/u/6007097?v=4)](https://github.com/scotwells "scotwells (1 commits)")

---

Tags

phpredisqueuejobbackgroundresquephp-resqueworker

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/giovanne-oliveira-php-resque/health.svg)

```
[![Health](https://phpackages.com/badges/giovanne-oliveira-php-resque/health.svg)](https://phpackages.com/packages/giovanne-oliveira-php-resque)
```

###  Alternatives

[mjphaynes/php-resque

Redis backed library for creating background jobs and processing them later.

225198.8k2](/packages/mjphaynes-php-resque)[spinx/sidekiq-job-php

Push and schedule jobs to Sidekiq from PHP

37214.7k](/packages/spinx-sidekiq-job-php)

PHPackages © 2026

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