/**
  * Run to start workers
  */
 public function run()
 {
     if (empty($this->queues)) {
         die('Set queues var containing the list of queues to work.' . PHP_EOL);
     }
     Resque::setBackend($this->redisBackend, $this->database, $this->password);
     if ($this->count > 1) {
         for ($i = 0; $i < $this->count; ++$i) {
             $pid = pcntl_fork();
             if ($pid == -1) {
                 die('Could not fork worker ' . $i . PHP_EOL);
             } elseif (!$pid) {
                 // Child, start the worker
                 $this->_startWorker();
                 break;
             }
         }
     } else {
         if (!empty($this->pidFile)) {
             file_put_contents($this->pidFile, getmypid()) or die('Could not write PID information to ' . $PIDFILE . PHP_EOL);
         }
         // Start a single worker
         $this->_startWorker();
     }
 }
示例#2
0
 /**
  * Initializes the connection.
  */
 public function init()
 {
     parent::init();
     Resque::setBackend($this->server . ':' . $this->port, $this->database, $this->password);
     if ($this->prefix) {
         Resque::redis()->prefix($this->prefix);
     }
 }
示例#3
0
<?php

require_once __DIR__ . '/../autoload.php';
use resque\Resque;
if (empty($argv[1])) {
    die('Specify the name of a job to add. e.g, php queue.php PHP_Job');
}
date_default_timezone_set('GMT');
// Resque::setBackend('127.0.0.1:6379', 0, 'your password');
Resque::setBackend('127.0.0.1:6379');
$args = array('time' => time(), 'array' => array('test' => 'test'));
$jobId = Resque::enqueue('default', $argv[1], $args, true);
echo "Queued job " . $jobId . "\n\n";
    echo "Cannot find redis-server in path. Please make sure redis is installed.\n";
    exit(1);
}
exec('cd ' . TEST_MISC . '; redis-server ' . REDIS_CONF, $output, $returnVar);
usleep(500000);
if ($returnVar != 0) {
    echo "Cannot start redis-server.\n";
    exit(1);
}
// Get redis port from conf
$config = file_get_contents(REDIS_CONF);
if (!preg_match('#^\\s*port\\s+([0-9]+)#m', $config, $matches)) {
    echo "Could not determine redis port from redis.conf";
    exit(1);
}
Resque::setBackend('localhost:' . $matches[1]);
// Shutdown
function killRedis($pid)
{
    if (getmypid() !== $pid) {
        return;
        // don't kill from a forked worker
    }
    $config = file_get_contents(REDIS_CONF);
    if (!preg_match('#^\\s*pidfile\\s+([^\\s]+)#m', $config, $matches)) {
        return;
    }
    $pidFile = TEST_MISC . '/' . $matches[1];
    if (file_exists($pidFile)) {
        $pid = trim(file_get_contents($pidFile));
        posix_kill((int) $pid, 9);
示例#5
0
 /**
  * 异常日志入队列
  *
  * @access public
  * @return void
  */
 public function errorLog()
 {
     if (isset(Application::app()->getConfig()->application->queue) && isset(Application::app()->getConfig()->application->queue->redis) && isset(Application::app()->getConfig()->application->queue->log)) {
         $queue = Application::app()->getConfig()->application->queue->toArray();
         $redis_config = $queue['redis'];
         $server = $redis_config['host'] . ':' . $redis_config['port'];
         $database = isset($redis_config['database']) ? $redis_config['database'] : null;
         Resque::setBackend($server, $database);
         $args = array('module' => $queue['log']['module'], 'controller' => $queue['log']['controller'], 'action' => $queue['log']['action'], 'args' => $this->toArray());
         $queue_name = Application::app()->getConfig()->application->queue->log->name;
         Resque::enqueue($queue_name, 'Resque\\Job\\YafCLIRequest', $args, true);
     }
 }