phresque / phresque
A background processing implementation inspired by php-resque
Installs: 7 484
Dependents: 1
Suggesters: 0
Security: 0
Stars: 18
Watchers: 8
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.0
- mtdowling/cron-expression: *
- phresque/spork: *
- psr/log: *
Requires (Dev)
- irediscent/irediscent: *
- phpunit/phpunit: *
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2018-11-29 12:30:17 UTC
README
Phresque is a clustered queuing system for PHP with a redis backend, built from the ground up to provide bulletproof reliability.
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
- https://github.com/resque/resque Original Ruby/Redis queue system developed by the guys at GitHub
- https://github.com/chrisboulton/php-resque Chris Boulton's Original PHP port of resque
- https://github.com/kamisama/Fresque Kamisama's php-resque manager
- https://github.com/Sonido/Sonido A nice but incomplete re-implementation of the php-resque with DI