2017 © Pedro Peláez
 

cakephp-plugin cakephp-gearman

Gearman utilities for CakePHP

image

lorenzo/cakephp-gearman

Gearman utilities for CakePHP

  • Saturday, June 18, 2016
  • by lorenzo
  • Repository
  • 3 Watchers
  • 12 Stars
  • 744 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

cakephp-gearman

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)

Installation

  1. install the gearman php extension ( @see http://gearman.org/getting-started/ for instructions )
  2. install the joze_zap's cakephp gearman plugin (clone it and load it like u usually do with other cake plugins)
  3. 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
        }
    }

}

The Versions

18/06 2016

dev-master

9999999-dev https://github.com/lorenzo/cakephp-gearman

Gearman utilities for CakePHP

  Sources   Download

MIT

The Requires

 

cakephp server queue gearman