lorenzo / cakephp-gearman
Gearman utilities for CakePHP
Installs: 761
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 2
Forks: 2
Open Issues: 0
Type:cakephp-plugin
Requires
- php: >=5.3.0
- composer/installers: *
This package is auto-updated.
Last update: 2019-04-25 10:23:18 UTC
README
Gearman utilities for CakePHP
Cakephp-Gearman is a plugin to integrate gearman into cakephp applications.
This repository is no longer maintained. You might want to try cvo-technologies/cakephp-gearman instead.
Installation
- install the gearman php extension ( @see http://gearman.org/getting-started/ for instructions )
- install the joze_zap's cakephp gearman plugin (clone it and load it like u usually do with other cake plugins)
- implement your own Shell with
php public $tasks = ['Gearman.GearmanWorker'];
Example Usage
App::uses('GearmanQueue', 'Gearman.Client'); class SomeController extends AppController{ public function Somefunction(){ //do awesome stuff GearmanQueue::execute('build_newsletter', ['User' => $user]); } }
App::uses('AppShell', 'Console/Command'); App::uses('CakeEmail', 'Network/Email'); /** * This class is responsible for building email templates per user and sending them as newsletter * */ class NewsletterShell extends AppShell { /** * List of Tasks to be used * * @return void */ public $tasks = ['Gearman.GearmanWorker']; /** * Starts a worker server and make it ready to serve new build_newsletter jobs * * @return void */ public function server() { $this->GearmanWorker->addFunction('build_newsletter', $this, 'sendNewsLetter'); $this->GearmanWorker->work(); } /** * Builds and sends a newsletter to a user for an specific location * * @param array $data containing 'user' and 'location' keys * @return void */ public function sendNewsLetter($data) { $Email = new CakeEmail('smtp'); try{ $Email->template('exampleContent', 'someLayout') ->to($data['User']['email']) ->subject('First Gearman email.') ->emailFormat('text') ->viewVars(array('data' => $data)) ->send(); }catch(Exception $e){ //handle error } } }