PHPackages                             ride/lib-queue - 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. ride/lib-queue

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

ride/lib-queue
==============

Abstraction library for a job queue

1.3.0(6y ago)11.5k7MITPHP

Since Aug 11Pushed 6y ago9 watchersCompare

[ Source](https://github.com/all-ride/ride-lib-queue)[ Packagist](https://packagist.org/packages/ride/lib-queue)[ RSS](/packages/ride-lib-queue/feed)WikiDiscussions develop Synced today

READMEChangelogDependencies (2)Versions (7)Used By (7)

Ride: Queue Library
===================

[](#ride-queue-library)

Queue abstraction library of the PHP Ride framework.

Use a queue system for time-consuming tasks.

What's In This Library
----------------------

[](#whats-in-this-library)

### QueueJob

[](#queuejob)

The *QueueJob* interface is for you to implement. It holds the logic to run your task.

Your job implementation will probably need data to work with. Instead of attaching initialized objects to your job, you should attach references to the needed data, like id's. It will make your job smaller to store since id's are easier to serialize then object instances.

When your job is invoked, you should lookup your data, using the references, in the current state instead of the state when the job was queued.

### QueueManager

[](#queuemanager)

The *QueueManager* interface is to be implemented for the underlying queue system. This is the facade to the queue system. You can check the status of the system, a queue or a job. It's also used to queue jobs and to update their status.

The *QueueJob* interface receives the *QueueManager* when it's invoked. The queue manager should be extended so it can be used by queue jobs to lookup their references.

### QueueJobStatus

[](#queuejobstatus)

When you ask information about queue jobs, the *QueueManager* will return *QueueJobStatus* instances. This interface is also to be implemented by the underlying queue system.

### QueueDispatcher

[](#queuedispatcher)

A *QueueJob* holds the queue it is in. When you create a job, you might not know about the available queues or their availability. You can use a *QueueDispatcher* to queue the job. This dispatcher's goal is to select the proper queue for the job and perform the queueing process.

There are 2 dispatchers provided by the library.

#### SingleQueueDispatcher

[](#singlequeuedispatcher)

The *SingleQueueDispatcher* is a very simple dispatcher. It's used when you have only one static queue.

#### RoundRobinQueueDispatcher

[](#roundrobinqueuedispatcher)

The *RoundRobinQueueDispatcher* is initialized with a number of queues. When this dispatcher queues a job, it will push it to the queue with the least amount of jobs pending.

### QueueWorker

[](#queueworker)

A *QueueWorker* is used to grab jobs from the queue, and invoke them. This work process is most likely a command or daemon which runs in the background. You will need a worker for each queue.

A generic implementation is provided with the *GenericQueueWorker* class.

Code Sample
-----------

[](#code-sample)

Check this code sample to see some possibilities of this library:

```
