phresque/phresque

This package is abandoned and no longer maintained. No replacement package was suggested.

A background processing implementation inspired by php-resque

v4.0 2015-10-29 22:38 UTC

README

Phresque is a clustered queuing system for PHP with a redis backend, built from the ground up to provide bulletproof reliability.

Build Status Coverage Status

Creating a Job

// On the client
$phresque = new Phresque\Phresque();

// $phresque->make($class, $arguments = array());

$job = $phresque->make('ExampleJob', array('arg1' => 1,'arg2' => 'two'))
         ->in(10)          // Seconds to wait before executing (optional)
         ->lock()          // Don't allow another job of this name with the same arguments to run concurrently
         ->to('default');  // The job is now pushed to the queue 'default'. This should be the last method you call
// A sample job class - must be available on each worker
Class ExampleJob implements \Phresque\Job\JobInterface {
   
   protected $job;
   
   public function setJob(\Phresque\Model\Job $job)
   {
      $this->job = $job
   }
   
   public function perform()
   {
      var_dump($this->job->getArguments());
   }
}

Running Jobs

Create a script on the worker nodes containing the code below - run script multiple times or on multiple servers to create an array of worker nodes. Any free node will pick up the next job


// On the workers

$redisClient = new Irediscent\Irediscent(); // Or a compatible redis client of your choice eg. Predis\Client

$phresque = new Phresque\Phresque($redisClient);

$daemon = $this->phresque->worker('worker1'); // Hostname is used by default, but you can specify if required

$daemon->setLogger(new Monolog\Logger); // Optionally add a Psr\Log\LoggerInterface compatible logger

$daemon->run(); // Worker is now running

Insipration for parts of this library came from