public static function sendMessage($body) { if (Yii::app()->params['USE_BEANSTALK'] === '0') { return false; } //Connect to the queue $queue = new Phalcon\Queue\Beanstalk(array('host' => Yii::app()->params['BEANSTALK_SERVER'], 'port' => Yii::app()->params['BEANSTALK_PORT'])); $queue->choose(Yii::app()->params['TUBE_PLAY_HISTORY']); //Insert the job in the queue $queue->put($body); }
public function sendAction() { $config = ['driver' => 'smtp', 'host' => 'Host URL', 'port' => 587, 'encryption' => 'tls', 'username' => '*****@*****.**', 'password' => 'API secret key', 'from' => ['email' => '*****@*****.**', 'name' => 'Customer Support']]; $mailer = new \Phalcon\Ext\Mailer\Manager($config); $queue = new Phalcon\Queue\Beanstalk(array('host' => '127.0.0.1', 'port' => '11300')); $queue->put(array('sendEmail' => rand())); while (($job = $queue->peekReady()) !== false) { $to = $this->request->getPost('to'); $subject = $this->request->getPost('subject'); $content = $this->request->getPost('content'); $message = $mailer->createMessage()->to($to)->subject($subject)->content($content); $message->send(); $job->delete(); } return $this->flash->success("Email has been put to the queue!"); }
public function testBasic() { $queue = new Phalcon\Queue\Beanstalk(); try { @$queue->connect(); } catch (Exception $e) { $this->markTestSkipped($e->getMessage()); return; } $expected = array('processVideo' => 4871); $queue->put($expected); while (($job = $queue->peekReady()) !== false) { $actual = $job->getBody(); $job->delete(); $this->assertEquals($expected, $actual); } }
public function testReleaseKickBury() { $queue = new Phalcon\Queue\Beanstalk(); try { @$queue->connect(); } catch (Exception $e) { $this->markTestSkipped($e->getMessage()); return; } $this->assertTrue($queue->choose('beanstalk-test') !== false); $task = 'doSomething'; $this->assertTrue($queue->put($task) !== false); $this->assertTrue($queue->watch('beanstalk-test') !== false); $job = $queue->reserve(0); $this->assertTrue($job !== false); $this->assertEquals($task, $job->getBody()); $this->assertTrue($job->touch()); // Release the job; it moves to the ready queue $this->assertTrue($job->release()); $job = $queue->reserve(0); $this->assertTrue($job !== false); $this->assertEquals($task, $job->getBody()); // Bury the job $this->assertTrue($job->bury()); $job = $queue->peekBuried(); $this->assertTrue($job !== false); $this->assertEquals($task, $job->getBody()); // Kick the job, it should move to the ready queue again // kick-job is supported since 1.8 if (false !== $job->kick()) { $job = $queue->peekReady(); $this->assertTrue($job !== false); $this->assertEquals($task, $job->getBody()); } $this->assertTrue($job->delete()); }
foreach ($mysqlRs as $value) { $id = $value["id"]; if (!strstr($value["redword"], "+")) { continue; } echo $value["keyword"] . "\n"; echo $value["redword"]; echo "\n"; $redword = str_replace("+", "", $value["redword"]); $redword = preg_replace("/[\\s]+/is", " ", $redword); echo $redword; echo "\n"; $conn->update("update gckeyword.key_proword set redword = '" . $redword . "' where id = '" . $value["id"] . "'"); try { $beanstalk->choose('v3www_prokeyword_cachewrite'); echo $beanstalk->put($value["keyword"], array('priority' => 1024, 'delay' => 0, 'ttr' => 86400)), "\n"; } catch (\Exception $e) { } exit; } } class Config { public static $dbArr = array('localhost' => array('192.168.12.70', "root", "123456", "test"), 'online' => array('192.168.2.163', "gongchangdb", "gongchangdb7232275", "caijiproductinfo"), 'info' => array('192.168.2.101', 'hangye', 'hangye7232275', 'hangye'), 'local' => array('192.168.8.18', 'root', 'gc7232275', 'gcoperate'), "local170" => array('192.168.8.170', "root", "gc7232275", "test"), 'local189' => array('192.168.8.189', 'gongchang', 'gongchang123', 'gckeyword'), 'main' => array('read.mysql.ch.gongchang.com', 'gcwork', 'gcwork7232275', 'catesearch'), 'maind' => array('write.mysql.ch.gongchang.com', 'gcwork', 'gcwork7232275', 'catesearch'), "product" => array("pdinfo.read.mysql.ch.gongchang.com", "gccontent", "gccontent7232275", "caijiproductinfo"), 'club' => array('55651c3e54ae6.sh.cdb.myqcloud.com', 'cdb_outerroot', 'ScIwH*3fEB(', 'cn_clubnew', 8287), 'txonline' => array('172.17.18.4', 'gckeyword', 'WVwVaxADjX9z3PHd', 'gckeyword')); public static $cateApiUrl = 'http://cate.ch.gongchang.com/cate_json/'; } class Table { public $conn = ''; public $config; public function __construct($connName)
<?php /** * 初始化一条企业关键词的beanstalk数据 */ define("App", "product"); if (App == "dev") { $config = array('192.168.8.189', 11300); } elseif (App == "product") { $config = array('172.17.16.101', 11300); } elseif (App == "test") { } else { exit("未知的环境!"); } $queue = new \Phalcon\Queue\Beanstalk(array("host" => $config[0], "port" => $config[1])); try { $queue->choose('v3www_comkeyword_init'); echo $queue->put("机械机床护罩", array('priority' => 1024, 'delay' => 0, 'ttr' => 86400)), "\n"; } catch (\Exception $e) { }
public function testStats() { $queue = new Phalcon\Queue\Beanstalk(); try { @$queue->connect(); } catch (Exception $e) { $this->markTestSkipped($e->getMessage()); return; } $this->assertTrue($queue->choose('beanstalk-test') !== false); $queueStats = $queue->stats(); $this->assertTrue(is_array($queueStats)); $tubeStats = $queue->statsTube('beanstalk-test'); $this->assertTrue(is_array($tubeStats)); $this->assertTrue($tubeStats['name'] === 'beanstalk-test'); $this->assertTrue($queue->statsTube('beanstalk-test-does-not-exist') === false); $this->assertTrue($queue->choose('beanstalk-test') !== false); $queue->put('doSomething'); $queue->watch('beanstalk-test'); $job = $queue->peekReady(); $jobStats = $job->stats(); $this->assertTrue(is_array($jobStats)); $this->assertTrue($jobStats['tube'] === 'beanstalk-test'); }
<?php /** * 初始化一条产品关键词的beanstalk数据 */ define("App", "product"); if (App == "dev") { $config = array('192.168.8.189', 11300); } elseif (App == "product") { $config = array('172.17.16.101', 11300); } elseif (App == "test") { } else { exit("未知的环境!"); } $queue = new \Phalcon\Queue\Beanstalk(array("host" => $config[0], "port" => $config[1])); try { $queue->choose('v3www_prokeyword_rela'); echo $queue->put(9942738, array('priority' => 1024, 'delay' => 0, 'ttr' => 86400)), "\n"; } catch (\Exception $e) { }
<?php //Connect to the queue $queue = new Phalcon\Queue\Beanstalk(array('host' => '192.168.0.21')); //Insert the job in the queue $queue->put(array('processVideo' => 4871));
<?php /** * 打入相关关键词预热脚本 */ $id = 46607377; $config = array('172.17.16.101', 11300); $queue = new \Phalcon\Queue\Beanstalk(array("host" => $config[0], "port" => $config[1])); $conn = new Table("txonline"); $keywordRs = $conn->findAll("select id, keyword from gckeyword.key_proword where id >=46607318 and id <= 46607375 limit 100"); foreach ($keywordRs as $value) { echo $value["id"] . "\n"; try { $queue->choose('v3www_prokeyword_rela'); echo $queue->put($value["id"], array('priority' => 1024, 'delay' => 0, 'ttr' => 86400)), "\n"; } catch (\Exception $e) { } } class Config { public static $dbArr = array('localhost' => array('192.168.12.70', "root", "123456", "test"), 'online' => array('192.168.2.163', "gongchangdb", "gongchangdb7232275", "caijiproductinfo"), 'info' => array('192.168.2.101', 'hangye', 'hangye7232275', 'hangye'), 'local' => array('192.168.8.18', 'root', 'gc7232275', 'gcoperate'), "local170" => array('192.168.8.170', "root", "gc7232275", "test"), 'local189' => array('192.168.8.189', 'gongchang', 'gongchang123', 'gckeyword'), 'main' => array('read.mysql.ch.gongchang.com', 'gcwork', 'gcwork7232275', 'catesearch'), 'maind' => array('write.mysql.ch.gongchang.com', 'gcwork', 'gcwork7232275', 'catesearch'), "product" => array("pdinfo.read.mysql.ch.gongchang.com", "gccontent", "gccontent7232275", "caijiproductinfo"), 'club' => array('55651c3e54ae6.sh.cdb.myqcloud.com', 'cdb_outerroot', 'ScIwH*3fEB(', 'cn_clubnew', 8287), 'txonline' => array('172.17.18.4', 'gckeyword', 'WVwVaxADjX9z3PHd', 'gckeyword')); public static $cateApiUrl = 'http://cate.ch.gongchang.com/cate_json/'; } class Table { public $conn = ''; public $config; public function __construct($connName) { $db = Config::$dbArr; $this->config = $db[$connName];
private function queueNotification() { $config = DI::getDefault()->getConfig(); $queue = new Phalcon\Queue\Beanstalk(array('host' => $config->monitor->beanstalkHost, 'port' => $config->monitor->beanstalkPort)); $queue->put(array('GatewayStatusUpdate' => $this->ID)); }