Download the PHP package sinacloud/php-resque without Composer

On this page you can find all versions of the php package sinacloud/php-resque. 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 php-resque

php-resque: PHP Resque Worker (and Enqueue) Build Status

Resque is a Redis-backed library for creating background jobs, placing those jobs on one or more queues, and processing them later.

Background

Resque was pioneered and is developed by the fine folks at GitHub (yes, I am a kiss-ass), and written in Ruby. What you're seeing here is an almost direct port of the Resque worker and enqueue system to PHP.

For more information on Resque, visit the official GitHub project: https://github.com/resque/resque

For further information, see the launch post on the GitHub blog: http://github.com/blog/542-introducing-resque

The PHP port does NOT include its own web interface for viewing queue stats, as the data is stored in the exact same expected format as the Ruby version of Resque.

The PHP port provides much the same features as the Ruby version:

It also supports the following additional features:

Requirements

Getting Started

The easiest way to work with php-resque is when it's installed as a Composer package inside your project. Composer isn't strictly required, but makes life a lot easier.

If you're not familiar with Composer, please see http://getcomposer.org/.

  1. Add php-resque to your application's composer.json.

  2. Run composer install.

  3. If you haven't already, add the Composer autoload to your project's initialization file. (example)

Jobs

Queueing Jobs

Jobs are queued as follows:

Defining Jobs

Each job should be in its own class, and include a perform method.

When the job is run, the class will be instantiated and any arguments will be set as an array on the instantiated object, and are accessible via $this->args.

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.

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.

Dequeueing Jobs

This method can be used to conveniently remove a job from a queue.

If no jobs are given, this method will dequeue all jobs matching the provided queue.

Tracking Job Statuses

php-resque has the ability to perform basic status tracking of a queued job. The status information will allow you to check if a job is in the queue, is currently being run, has finished, or has failed.

To track the status of a job, pass true as the fourth argument to Resque::enqueue. A token used for tracking the job status will be returned:

To fetch the status of a job:

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

Statuses are available for up to 24 hours after a job has completed or failed, and are then automatically expired. A status can also forcefully be expired by calling the stop() method on a status class.

Workers

Workers work in the exact same way as the Ruby workers. For complete documentation on workers, see the original documentation.

A basic "up-and-running" bin/resque file is included that sets up a running worker environment. (vendor/bin/resque when installed via Composer)

The exception to the similarities with the Ruby version of resque is how a worker is initially setup. To work under all environments, not having a single environment such as with Ruby, the PHP port makes no assumptions about your setup.

To start a worker, it's very similar to the Ruby version:

It's your responsibility to tell the worker which file to include to get your application underway. You do so by setting the APP_INCLUDE environment variable:

Pro tip: Using Composer? More than likely, you don't need to worry about APP_INCLUDE, because hopefully Composer is responsible for autoloading your application too!

Getting your application underway also includes telling the worker your job classes, by means of either an autoloader or including them.

Alternately, you can always include('bin/resque') from your application and skip setting APP_INCLUDE altogether. Just be sure the various environment variables are set (setenv) before you do.

Logging

The port supports the same environment variables for logging to STDOUT. Setting VERBOSE will print basic debugging information and VVERBOSE will print detailed information.

Priorities and Queue Lists

Similarly, priority and queue list functionality works exactly the same as the Ruby workers. Multiple queues should be separated with a comma, and the order that they're supplied in is the order that they're checked in.

As per the original example:

The file_serve queue will always be checked for new jobs on each iteration before the warm_cache queue is checked.

Running All Queues

All queues are supported in the same manner and processed in alphabetical order:

Running Multiple Workers

Multiple workers can be launched simultaneously by supplying the COUNT environment variable:

Be aware, however, that each worker is its own fork, and the original process will shut down as soon as it has spawned COUNT forks. If you need to keep track of your workers using an external application such as monit, you'll need to work around this limitation.

Custom prefix

When you have multiple apps using the same Redis database it is better to use a custom prefix to separate the Resque data:

Forking

Similarly to the Ruby versions, supported platforms will immediately fork after picking up a job. The forked child will exit as soon as the job finishes.

The difference with php-resque is that if a forked child does not exit nicely (PHP error or such), php-resque will automatically fail the job.

Signals

Signals also work on supported platforms exactly as in the Ruby version of Resque:

Process Titles/Statuses

The Ruby version of Resque has a nifty feature whereby the process title of the worker is updated to indicate what the worker is doing, and any forked children also set their process title with the job being run. This helps identify running processes on the server and their resque status.

PHP does not have this functionality by default until 5.5.

A PECL module (http://pecl.php.net/package/proctitle) exists that adds this functionality to PHP before 5.5, so if you'd like process titles updated, install the PECL module as well. php-resque will automatically detect and use it.

Event/Hook System

php-resque has a basic event system that can be used by your application to customize how some of the php-resque internals behave.

You listen in on events (as listed below) by registering with Resque_Event and supplying a callback that you would like triggered when the event is raised:

[callback] may be anything in PHP that is callable by call_user_func_array:

Events may pass arguments (documented below), so your callback should accept these arguments.

You can stop listening to an event by calling Resque_Event::stopListening with the same arguments supplied to Resque_Event::listen.

It is up to your application to register event listeners. When enqueuing events in your application, it should be as easy as making sure php-resque is loaded and calling Resque_Event::listen.

When running workers, if you run workers via the default bin/resque script, your APP_INCLUDE script should initialize and register any listeners required for operation. If you have rolled your own worker manager, then it is again your responsibility to register listeners.

A sample plugin is included in the extras directory.

Events

beforeFirstFork

Called once, as a worker initializes. Argument passed is the instance of Resque_Worker that was just initialized.

beforeFork

Called before php-resque forks to run a job. Argument passed contains the instance of Resque_Job for the job about to be run.

beforeFork is triggered in the parent process. Any changes made will be permanent for as long as the worker lives.

afterFork

Called after php-resque forks to run a job (but before the job is run). Argument passed contains the instance of Resque_Job for the job about to be run.

afterFork is triggered in the child process after forking out to complete a job. Any changes made will only live as long as the job is being processed.

beforePerform

Called before the setUp and perform methods on a job are run. Argument passed contains the instance of Resque_Job for the job about to be run.

You can prevent execution of the job by throwing an exception of Resque_Job_DontPerform. Any other exceptions thrown will be treated as if they were thrown in a job, causing the job to fail.

afterPerform

Called after the perform and tearDown methods on a job are run. Argument passed contains the instance of Resque_Job that was just run.

Any exceptions thrown will be treated as if they were thrown in a job, causing the job to be marked as having failed.

onFailure

Called whenever a job fails. Arguments passed (in this order) include:

beforeEnqueue

Called immediately before a job is enqueued using the Resque::enqueue method. Arguments passed (in this order) include:

You can prevent enqueing of the job by throwing an exception of Resque_Job_DontCreate.

afterEnqueue

Called after a job has been queued using the Resque::enqueue method. Arguments passed (in this order) include:

Step-By-Step

For a more in-depth look at what php-resque does under the hood (without needing to directly examine the code), have a look at HOWITWORKS.md.

Contributors

Project Lead

Others


All versions of php-resque with dependencies

PHP Build Version
Package Version
Requires php Version >=5.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 sinacloud/php-resque contains the following files

Loading the files please wait ....