Download the PHP package igorsantos07/phalcon-queue-db without Composer

On this page you can find all versions of the php package igorsantos07/phalcon-queue-db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phalcon-queue-db

Phalcon package for Queue through the Database

StyleCI Build Status Latest Version

This package sits side by side with \Phalcon\Queue\Beanstalk as a way to provide job queuing for those who don't want to bother with installing and maintaining a Beanstalk server.

This is mostly useful when you have a low throughput of jobs. It is advised to use something faster such as Beanstalk if you plan to have a lot of jobs and workers happening at the same time - as that may put a lot of strain in your database and disk I/O, slowing jobs down.

Installation

  1. drop this package in your composer installation: composer require igorsantos07/phalcon-queue-db
  2. create the needed table by importing one of the files from sql/. You may copy it into a migration or whatever it's needed in your setup to get a new table up and running :)
  3. Read the rest of this doc to know how to use it and profit!

Usage

As most job queuing systems, the idea here is to take off some load of a part of the application and run that outside. Thus, there are two parts that interact together: when you [queue a job][#job-queuing], and when you [work on it][#job-processing].

As this package is based upon the original Beanstalk implementation by Phalcon, you may also find useful to read both the base-class documentation and an almost complete tutorial on Beanstalk. It is good to warn, though, that there are other features implemented that are not covered by the original class, but we didn't follow some strict behaviours of Beanstalk as the base class didn't follow as well - we're striving for additional features without the cost of backwards compatibility.

For the following samples, consider the following uses:

Job queuing

The actual queue

To get the queue object, simply instantiate it. The sole argument is your database connection name, as found in Phalcon DI - the default is db. You may want to set the queue itself in your Dependency Injection container as well.

$queue = new DbQueue(); //gets a database connection named db from the DI
$outsiderQueue = new DbQueue('weird_db'); another queue, in another db?

Adding stuff to the queue

So, there's something you want to do later. Let's say you need to send a bunch of emails all at once, and that would take a while if happened during the user request. We have the concept of "job tubes", as in separate tubes get different types of jobs, allowing you to have specialized workers for each type of job.

If no tube is specified, the default one is called... you guessed it, "default".

Some useful pieces of code in this phase are:

One difference of the original Beanstalk implementation is: there's no need for the job body to be a string. As long as you give the job something serializable, you're good to go.

Job options

It's also possible to define some specific options for jobs.

We'll see how those interact in the next section, about retrieving jobs and working on them.

There are a couple of constants in the Job class that define other priority presets. If no priority is given, the default one is Job::PRIORITY_MEDIUM.

Job processing

From your command-line script (herein called worker), you can process jobs by using peek or reserve methods on the queue. Peek jobs are advised only for verifications and maintenance: actual work should be made on reserved jobs only.

Useful bits here:

Peeking into the queue

For maintenance tasks you can use various peeking methods to see the current queue status:

Remember that jobs are always ordered by priority and age: urgent jobs come always first, and then older jobs are returned in front of newer ones.

Kicking jobs back

To put a buried job back in the normal queue for processing, or to advance a delayed job in the line, you can use Job::kick(). If you want to move several buried jobs back in line at once, there's also DbQueue::kick($numberOfJobs).

Tip: you may want to create a separate database connection in the DI that is persistent. This way there will be no need to restart the connection every time the worker is called.

Maintenance

Last but not least, there's a number of helper methods to get you additional information on the your current queue state:

Bonus: the Job Model

As this is a database library, we do use models to interact with the actual database table. That said, you'll hardly ever need that.

Well, if you do need, you can retrieve the model related to a job by using Job::getModel(), or by using the Db\Model class directly.

Main differences from the original implementations

This is a non-exhaustive list of what changed between the original Beanstalk client, Phalcon's one, and our final implementation of a cool queue system.

From the basic Beanstalk client

The implementation reference here was Python's Beanstalkc

From Phalcon's Queue\Beanstalk

A couple of features were added, both to comply with the original Beanstalk client and to keep in line with other queuing systems found in PHP, such as Laravel's. There's a specific test (tests/unit/OriginalTest.php) that mimics the queue test from Phalcon codebase.

Keep in mind that some things here might also be an addition in comparison with the original client.


All versions of phalcon-queue-db with dependencies

PHP Build Version
Package Version
Requires ext-phalcon Version ^2.0.11 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package igorsantos07/phalcon-queue-db contains the following files

Loading the files please wait ....