lorenzo/cakephp-gearman

此包已被废弃且不再维护。作者建议使用cvo-technologies/cakephp-gearman包。

CakePHP的Gearman工具

安装: 761

依赖: 0

建议者: 0

安全: 0

星标: 14

关注者: 2

分支: 2

开放问题: 0

类型:cakephp-plugin

dev-master 2016-06-18 16:25 UTC

This package is auto-updated.

Last update: 2019-04-25 10:23:18 UTC


README

CakePHP的Gearman工具

Cakephp-Gearman是一个插件,用于将gearman集成到cakephp应用中。

此仓库不再维护。您可能想要尝试cvo-technologies/cakephp-gearman

安装

  1. 安装gearman php扩展(请参阅http://gearman.org/getting-started/获取说明)
  2. 安装joze_zap的cakephp gearman插件(克隆它,并像其他cake插件一样加载)
  3. 使用以下代码实现自己的Shell: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
        }
    }
 
}