本文整理汇总了PHP中Queue类的典型用法代码示例。如果您正苦于以下问题:PHP Queue类的具体用法?PHP Queue怎么用?PHP Queue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Queue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: queueGetter
function queueGetter($conn, $condition)
{
try {
if (empty($condition)) {
$tsql = "SELECT [id],[Name],[Location] FROM dbo.Queue";
} else {
$tsql = "SELECT [id],[Name],[Location] FROM dbo.Queue WHERE {$condition}";
}
$conn = OpenConnection();
$getQueues = sqlsrv_query($conn, $tsql);
if ($getQueues == FALSE) {
echo "Error!!<br>";
die(print_r(sqlsrv_errors(), true));
}
while ($row = sqlsrv_fetch_array($getQueues, SQLSRV_FETCH_ASSOC)) {
$queue = new Queue($row['Name'], $row['Location']);
$queue->setId($row['id']);
$queues[] = $queue;
}
sqlsrv_free_stmt($getQueues);
sqlsrv_close($conn);
if (!empty($queues)) {
return $queues;
} else {
return null;
}
} catch (Exception $e) {
echo "Get Queue Error!";
}
}
示例2: actionIndex
/**
* @param int $limit
*/
public function actionIndex($limit = 5)
{
$limit = (int) $limit;
$this->log("Try process {$limit} mail tasks...");
$queue = new Queue();
$models = $queue->getTasksForWorker(self::MAIL_WORKER_ID, $limit);
$this->log("Find " . count($models) . " new mail task");
foreach ($models as $model) {
$this->log("Process mail task id = {$model->id}");
$data = $model->decodeJson();
if (!$data) {
$model->completeWithError('Error json_decode', CLogger::LEVEL_ERROR);
$this->log("Error json_decode");
continue;
}
if (!isset($data['from'], $data['to'], $data['theme'], $data['body'])) {
$model->completeWithError('Wrong data...');
$this->log('Wrong data...', CLogger::LEVEL_ERROR);
continue;
}
$from = $this->from ? $this->from : $data['from'];
$replyTo = isset($data['replyTo']) ? $data['replyTo'] : [];
$sender = Yii::app()->getComponent($this->sender);
if ($sender->send($from, $data['to'], $data['theme'], $data['body'], false, $replyTo)) {
$model->complete();
$this->log("Success send mail");
continue;
}
$this->log('Error sending email', CLogger::LEVEL_ERROR);
}
}
示例3: buildResponse
/**
* Converts the response in JSON format to the value object i.e Queue
*
* @param json
* - response in JSON format
*
* @return Queue object filled with json data
*
*/
function buildResponse($json)
{
$queuesJSONObj = $this->getServiceJSONObject("queues", $json);
$queueJSONObj = $queuesJSONObj->__get("queue");
$queue = new Queue();
$queue->setStrResponse($json);
$queue->setResponseSuccess($this->isRespponseSuccess($json));
$this->buildObjectFromJSONTree($queue, $queueJSONObj);
if (!$queueJSONObj->has("messages")) {
return $queue;
}
if (!$queueJSONObj->__get("messages")->has("message")) {
return $queue;
}
if ($queueJSONObj->__get("messages")->__get("message") instanceof JSONObject) {
// Single Entry
$messageObj = new QueueMessage($queue);
$this->buildObjectFromJSONTree($messageObj, $queueJSONObj->__get("messages")->__get("message"));
} else {
// Multiple Entry
$messagesJSONArray = $queueJSONObj->getJSONObject("messages")->getJSONArray("message");
for ($i = 0; $i < count($messagesJSONArray); $i++) {
$messageJSONObj = $messagesJSONArray[$i];
$messageObj = new QueueMessage($queue);
$messageJSONObj = new JSONObject($messageJSONObj);
$this->buildObjectFromJSONTree($messageObj, $messageJSONObj);
}
}
return $queue;
}
示例4: work
public static function work(&$controllerContext, &$viewContext)
{
$queue = new Queue(Config::$userQueuePath);
$queueItem = new QueueItem(strtolower($controllerContext->userName));
$j['user'] = $controllerContext->userName;
$j['pos'] = $queue->seek($queueItem);
$viewContext->layoutName = 'layout-json';
$viewContext->json = $j;
}
示例5: testConsumeViaQueue
public function testConsumeViaQueue()
{
$this->markTestSkipped('Consuming via queue does not work');
$this->consumerTopic->consumeQueueStart(self::PARTITION, RD_KAFKA_OFFSET_BEGINNING, $this->queue);
$this->consumerTopic->consume(self::PARTITION, 100);
$this->consumerTopic->consumeStop(self::PARTITION);
$message = $this->queue->consume(200);
$this->assertInstanceOf(Message::class, $message);
}
示例6: getMqsLength
function getMqsLength($queuename)
{
include SERVER_ROOT . "libs/alimqs.class.php";
$QueueObj = new Queue('84KTqRKsyBIYnVJt', 'u72cpnMTt2mykMMluafimbhv5QD3uC', 'crok2mdpqp', 'mqs-cn-hangzhou.aliyuncs.com');
$info = $QueueObj->Getqueueattributes($queuename);
if ($info['state'] == 'ok') {
return $info['msg']['ActiveMessages'];
}
return false;
}
示例7: __construct
/**
* Constructor
*
* @param string $worker function name
* @param mixed $chanData
*/
public function __construct($worker, $chanData = null)
{
if ($chanData && is_array($chanData)) {
foreach ($chanData as $chanId => $jobs) {
$Q = new Queue($worker);
$Q->addJobs($jobs);
$this->chan[$chanId] = $Q;
}
}
}
示例8: preWork
public static function preWork(&$controllerContext, &$viewContext)
{
$controllerContext->cache->setPrefix($controllerContext->userName);
if (BanHelper::getUserBanState($controllerContext->userName) == BanHelper::USER_BAN_TOTAL) {
$controllerContext->cache->bypass(true);
$viewContext->userName = $controllerContext->userName;
$viewContext->viewName = 'error-user-blocked';
$viewContext->meta->title = 'User blocked — ' . Config::$title;
return;
}
$module = $controllerContext->module;
HttpHeadersHelper::setCurrentHeader('Content-Type', $module::getContentType());
$viewContext->media = $controllerContext->media;
$viewContext->module = $controllerContext->module;
$viewContext->meta->noIndex = true;
$viewContext->contentType = $module::getContentType();
if ($viewContext->contentType != 'text/html') {
$viewContext->layoutName = 'layout-raw';
}
Database::selectUser($controllerContext->userName);
$user = R::findOne('user', 'LOWER(name) = LOWER(?)', [$controllerContext->userName]);
if (empty($user)) {
if (!isset($_GET['referral']) || $_GET['referral'] !== 'search') {
$controllerContext->cache->bypass(true);
$viewContext->userName = $controllerContext->userName;
$viewContext->viewName = 'error-user-not-found';
$viewContext->meta->title = 'User not found — ' . Config::$title;
return;
}
$queue = new Queue(Config::$userQueuePath);
$queueItem = new QueueItem(strtolower($controllerContext->userName));
$queue->enqueue($queueItem);
$viewContext->queuePosition = $queue->seek($queueItem);
$controllerContext->cache->bypass(true);
//try to load cache, if it exists
$url = $controllerContext->url;
if ($controllerContext->cache->exists($url)) {
$controllerContext->cache->load($url);
flush();
$viewContext->layoutName = null;
$viewContext->viewName = null;
return;
}
$viewContext->userName = $controllerContext->userName;
$viewContext->viewName = 'error-user-enqueued';
$viewContext->meta->title = 'User enqueued — ' . Config::$title;
return;
}
$viewContext->user = $user;
$viewContext->meta->styles[] = '/media/css/menu.css';
$viewContext->updateWait = Config::$userQueueMinWait;
$module = $controllerContext->module;
$module::preWork($controllerContext, $viewContext);
}
示例9: testAddItemEmpty
/**
* @dataProvider providerAddItemsEmpty
*/
public function testAddItemEmpty($invalidItem = null)
{
$queue = new Queue($this->redis, 'test');
$queue->addItem(1);
try {
$queue->addItem($invalidItem);
$this->fail('Expected \\PhpRQ\\Exception\\InvalidArgument to be thrown');
} catch (Exception\InvalidArgument $e) {
}
$this->assertSame(['1'], $this->redis->lrange('test', 0, 5));
$this->assertKeys(['test']);
}
示例10: load_view
function load_view($id)
{
global $cp;
$objQueue = new Queue();
$objQueue->setUid($id);
if ($objQueue->load()) {
$cp->set_data(nl2br($objQueue->getBbs('description')));
} else {
$cp->set_data('item not found!');
}
return;
}
示例11: enqueueOnce
public function enqueueOnce(Job $job, $trackStatus = false)
{
$queue = new Queue($job->queue);
$jobs = $queue->getJobs();
foreach ($jobs as $j) {
if ($j->job->payload['class'] == get_class($job)) {
if (count(array_intersect($j->args, $job->args)) == count($job->args)) {
return $trackStatus ? $j->job->payload['id'] : null;
}
}
}
return $this->enqueue($job, $trackStatus);
}
示例12: work
public static function work(&$controllerContext, &$viewContext)
{
$queue = new Queue(Config::$userQueuePath);
$queueItem = new QueueItem(strtolower($controllerContext->userName));
$user = R::findOne('user', 'LOWER(name) = LOWER(?)', [$controllerContext->userName]);
$profileAge = time() - strtotime($user->processed);
$banned = BanHelper::getUserBanState($controllerContext->userName) != BanHelper::USER_BAN_NONE;
if ($profileAge > Config::$userQueueMinWait and !$banned && Config::$enqueueEnabled) {
$queue->enqueue($queueItem);
}
$j['user'] = $controllerContext->userName;
$j['pos'] = $queue->seek($queueItem);
$viewContext->layoutName = 'layout-json';
$viewContext->json = $j;
}
示例13: byQueue
public function byQueue($qid)
{
if (is_array($qid)) {
$obj = new Queue($qid);
$obj->setTimePeriod($this->startEpoch, $this->endEpoch);
$obj->setAgent($this->agent);
return $obj;
} else {
if (@is_object($this->qobjects[$qid])) {
return $this->qobjects[$qid];
} else {
return false;
}
}
}
示例14: addToQueque
/**
*
* @param string $type
* @param string $description
* @param string $function
* @param array $args
* @param int $priority
* @return type
*/
static function addToQueque($type, $description, $function, $args, $priority = 0)
{
$queue = new Queue();
$queue->setCreatedAt(time());
$queue->setStatus(self::STATUS_QUEUED);
$queue->setArguments(serialize($args));
$queue->setFunction($function);
$queue->setType($type);
$queue->setDescription($description);
$queue->setPriority($priority);
return $queue->save();
}
示例15: addToQueue
public static function addToQueue($queue, $ownerID, $vCode, $api, $scope)
{
// Prepare the auth array
if ($vCode != null) {
$auth = array('keyID' => $ownerID, 'vCode' => $vCode);
} else {
$auth = array();
}
// Check the databse if there are jobs outstanding ie. they have the status
// Queued or Working. If not, we will queue a new job, else just capture the
// jobID and return that
$jobID = \SeatQueueInformation::where('ownerID', '=', $ownerID)->where('api', '=', $api)->whereIn('status', array('Queued', 'Working'))->first();
// Check if the $jobID was found, else, queue a new job
if (!$jobID) {
$jobID = \Queue::push($queue, $auth);
\SeatQueueInformation::create(array('jobID' => $jobID, 'ownerID' => $ownerID, 'api' => $api, 'scope' => $scope, 'status' => 'Queued'));
} else {
// To aid in potential capacity debugging, lets write a warning log entry so that a user
// is able to see that a new job was not submitted
\Log::warning('A new job was not submitted due a similar one still being outstanding. Details: ' . $jobID, array('src' => __CLASS__));
// Set the jobID to the ID from the database
$jobID = $jobID->jobID;
}
return $jobID;
}