PHPackages                             phlib/jobqueue - 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. phlib/jobqueue

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

phlib/jobqueue
==============

Job Queue implementation.

3.2.1(4mo ago)28.3k↓29.6%1[2 issues](https://github.com/phlib/jobqueue/issues)LGPL-3.0PHPPHP ^8.1CI failing

Since Apr 25Pushed 4mo ago6 watchersCompare

[ Source](https://github.com/phlib/jobqueue)[ Packagist](https://packagist.org/packages/phlib/jobqueue)[ RSS](/packages/phlib-jobqueue/feed)WikiDiscussions main Synced yesterday

READMEChangelog (10)Dependencies (22)Versions (21)Used By (0)

phlib/jobqueue
==============

[](#phlibjobqueue)

[![Code Checks](https://camo.githubusercontent.com/aba9fd0aafdb1efee7053cd520cb1ec5d1f449c34101eedd7c118b0cee494758/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70686c69622f6a6f6271756575652f636f64652d636865636b732e796d6c3f6c6f676f3d676974687562)](https://github.com/phlib/jobqueue/actions/workflows/code-checks.yml)[![Codecov](https://camo.githubusercontent.com/12183cc8f971f65dcc4b4807fd481f9fcab394e0580b303d825e5488e93530e0/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f70686c69622f6a6f6271756575652e7376673f6c6f676f3d636f6465636f76)](https://codecov.io/gh/phlib/jobqueue)[![Latest Stable Version](https://camo.githubusercontent.com/4f91df8d1dd1b50f6427d3d6619c0aa10642bd5f5519747f8146dd7b88ff4c00/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70686c69622f6a6f6271756575652e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/jobqueue)[![Total Downloads](https://camo.githubusercontent.com/3862d3187c85f8dbf8955133a153f2ffe1ee2c4a3a709500562db7625a4933e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70686c69622f6a6f6271756575652e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/phlib/jobqueue)[![Licence](https://camo.githubusercontent.com/30a4da94b7a075ec4ff87dace4a014d3625b834fc38bf17a3a2a75403b146b51/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f6a6f6271756575652e737667)](https://camo.githubusercontent.com/30a4da94b7a075ec4ff87dace4a014d3625b834fc38bf17a3a2a75403b146b51/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686c69622f6a6f6271756575652e737667)

Job Queue implementation.

Install
-------

[](#install)

Via Composer

```
$ composer require phlib/jobqueue
```

or

```
"require": {
    "phlib/jobqueue": "*"
}
```

Basic Usage
-----------

[](#basic-usage)

Bootstrap

```
$beanstalk = (new \Phlib\Beanstalk\Factory())->create('localhost');
$db        = new \Phlib\Db\Adapter(['host' => '127.0.0.1', 'dbname' => 'example']);

$scheduler = new \Phlib\JobQueue\Scheduler\DbScheduler($db, 300, 600, true);
$jobQueue  = new \Phlib\JobQueue\Beanstalk\Scheduled($beanstalk, $scheduler);
```

Producer

```
$delay = strtotime('+1 week') - time();
$jobQueue->put('my-queue', ['my' => 'jobData'], ['delay' => $delay]);
```

Consumer

```
do {
    while ($job = $jobQueue->retrieve($queue)) {
        echo "Found new job {$job->getId()}\n", var_export($job->getBody(), true), "\n";
        $jobQueue->markAsComplete($job);
    }

    usleep(500);
} while (true);
```

See [examples](example/) for more advance usage.

Jobqueue Script
---------------

[](#jobqueue-script)

The script has a dependency on two constructed objects. The Job Queue interface and the Scheduler interface. In order to provide this the following describes how they are injected into the script.

jobqueue-config.php (can be located in the root or `config` folder.

```
