dev-master
9999999-dev https://github.com/lorenzo/cakephp-gearmanGearman utilities for CakePHP
MIT
The Requires
- php >=5.3.0
- composer/installers *
cakephp server queue gearman
Gearman utilities for CakePHP
Gearman utilities for CakePHP, (*1)
Cakephp-Gearman is a plugin to integrate gearman into cakephp applications., (*2)
This repository is no longer maintained. You might want to try cvo-technologies/cakephp-gearman instead., (*3)
php public $tasks = ['Gearman.GearmanWorker'];
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 } } }
Gearman utilities for CakePHP
MIT
cakephp server queue gearman