Esempio n. 1
0
 public static function getInstance($config)
 {
     $name = $config['name'];
     if (empty(self::$instance[$name])) {
         $beanstalk = new \Beanstalk();
         foreach ($config['servers'] as $server) {
             $beanstalk->addServer($server['host'], $server['port']);
         }
         self::$instances[$name] = $beanstalk;
     }
     return self::$instances[$name];
 }
Esempio n. 2
0
 * 
 *   sequential peek:    in a loop, pick the next server and peek-ready() ... etc.
 * 
 * the *peek modes have a companion setting, peek_usleep, which tells the client how long
 * to usleep() for between peeks to servers.
 * 
 * auto_unyaml -> if true, this causes the client to assume the presence of the syck yaml
 * parser, and attempts to 'unyamlize' yaml output for you before returning it.
 */
$beanstalk = BeanStalk::open(array('servers' => array('127.0.0.1:11300'), 'select' => 'random peek'));
// As in the protocol doc.
$beanstalk->use_tube('foo');
// As in the protocol doc.
$beanstalk->put(0, 0, 120, 'say hello world');
// Add a job to the queue with highest priority,
// no delay, 120 seconds TTR, with the contents
// 'say hello world'.
// NOTE: the put() method here supports a final optional
// argument, a tube name. If supplied, the server will
// first switch to that tube, write the job, then switch
// back to the old tube again.
// As in the protocol doc.
$job = $beanstalk->reserve();
// Assuming there was nothing in the queue before
// we started, this will give us our 'hello world'
// job back.
// This is a BeanQueueJob object.
echo $job->get();
// Output: 'say hello world'
Beanstalk::delete($job);
// Delete the job.
Esempio n. 3
0
 public static function PutJob($tube, $data, $delay = 0, $priority = Worker::MEDIUM_PRIORITY, $timeout = Worker::TIMEOUT)
 {
     static $beanstalk = null;
     if (is_null($beanstalk)) {
         $beanstalk = Beanstalk::open($GLOBALS['config']['beanstalk']);
     }
     static $tube_used = null;
     if ($tube_used != $tube) {
         $beanstalk->use_tube($tube);
         $tube_used = $tube;
     }
     $beanstalk->put($priority, $delay, $timeout, $data);
 }