Esempio n. 1
0
 public function testInteger($integer_1, $integer_2, $integer_3, $integer_4, $operation)
 {
     $args = new PhpAmqpLib_Wire_AMQPWriter();
     $args->write_octet($integer_1);
     $args->write_short($integer_2);
     $args->write_long($integer_3);
     $args->write_longlong($integer_4);
     $args->write_octet($operation);
     return array(120, 10, $args);
 }
 /**
  * Returns a new PhpAmqpLib_Wire_AMQPWriter or mutates the provided $pkt
  *
  * @param string $channel
  * @param int $class_id
  * @param int $weight
  * @param int $body_size
  * @param string $packed_properties
  * @param string $body
  * @param PhpAmqpLib_Wire_AMQPWriter $pkt
  * @return PhpAmqpLib_Wire_AMQPWriter
  */
 public function prepare_content($channel, $class_id, $weight, $body_size, $packed_properties, $body, $pkt = null)
 {
     if (empty($pkt)) {
         $pkt = new PhpAmqpLib_Wire_AMQPWriter();
     }
     // Content already prepared ?
     $key_cache = sprintf('%s|%s|%s|%s', $channel, $packed_properties, $class_id, $weight);
     if (!isset($this->prepare_content_cache[$key_cache])) {
         $w = new PhpAmqpLib_Wire_AMQPWriter();
         $w->write_octet(2);
         $w->write_short($channel);
         $w->write_long(mb_strlen($packed_properties, 'ASCII') + 12);
         $w->write_short($class_id);
         $w->write_short($weight);
         $this->prepare_content_cache[$key_cache] = $w->getvalue();
         if (count($this->prepare_content_cache) > $this->prepare_content_cache_max_size) {
             reset($this->prepare_content_cache);
             $old_key = key($this->prepare_content_cache);
             unset($this->prepare_content_cache[$old_key]);
         }
     }
     $pkt->write($this->prepare_content_cache[$key_cache]);
     $pkt->write_longlong($body_size);
     $pkt->write($packed_properties);
     $pkt->write_octet(0xce);
     // memory efficiency: walk the string instead of biting it. good for very large packets (close in size to memory_limit setting)
     $position = 0;
     $bodyLength = mb_strlen($body, 'ASCII');
     while ($position < $bodyLength) {
         $payload = mb_substr($body, $position, $this->frame_max - 8, 'ASCII');
         $position += $this->frame_max - 8;
         $pkt->write_octet(3);
         $pkt->write_short($channel);
         $pkt->write_long(mb_strlen($payload, 'ASCII'));
         $pkt->write($payload);
         $pkt->write_octet(0xce);
     }
     return $pkt;
 }
Esempio n. 3
0
 /**
  * @return array
  */
 public function basicNack($delivery_tag = 0, $multiple = false, $requeue = true)
 {
     $args = new PhpAmqpLib_Wire_AMQPWriter();
     $args->write_longlong($delivery_tag);
     $args->write_bits(array($multiple, $requeue));
     return array(60, 120, $args);
 }
 public function send_content($channel, $class_id, $weight, $body_size, $packed_properties, $body)
 {
     $pkt = new PhpAmqpLib_Wire_AMQPWriter();
     $pkt->write_octet(2);
     $pkt->write_short($channel);
     $pkt->write_long(strlen($packed_properties) + 12);
     $pkt->write_short($class_id);
     $pkt->write_short($weight);
     $pkt->write_longlong($body_size);
     $pkt->write($packed_properties);
     $pkt->write_octet(0xce);
     $pkt = $pkt->getvalue();
     $this->write($pkt);
     while ($body) {
         $payload = substr($body, 0, $this->frame_max - 8);
         $body = substr($body, $this->frame_max - 8);
         $pkt = new PhpAmqpLib_Wire_AMQPWriter();
         $pkt->write_octet(3);
         $pkt->write_short($channel);
         $pkt->write_long(strlen($payload));
         $pkt->write($payload);
         $pkt->write_octet(0xce);
         $pkt = $pkt->getvalue();
         $this->write($pkt);
     }
 }