public function testManagesHandles()
 {
     $m = curl_multi_init();
     $b = new BatchContext($m, true);
     $h = curl_init();
     $t = new Transaction(new Client(), new Request('GET', 'http://httbin.org'));
     $b->addTransaction($t, $h);
     $this->assertTrue($b->isActive());
     $this->assertSame($t, $b->findTransaction($h));
     $b->removeTransaction($t);
     $this->assertFalse($b->isActive());
     try {
         $this->assertEquals([], $b->findTransaction($h));
         $this->fail('Did not throw');
     } catch (\RuntimeException $e) {
     }
     curl_multi_close($m);
 }
Ejemplo n.º 2
0
 public function testCanCloseAll()
 {
     $m = curl_multi_init();
     $b = new BatchContext($m, true);
     $h = curl_init();
     $t = new Transaction(new Client(), new Request('GET', 'http://httbin.org'));
     $b->addTransaction($t, $h);
     $b->removeAll();
     $this->assertFalse($b->isActive());
     $this->assertEquals(0, count($this->readAttribute($b, 'handles')));
     curl_multi_close($m);
 }
Ejemplo n.º 3
0
 private function perform(BatchContext $context)
 {
     // The first curl_multi_select often times out no matter what, but is
     // usually required for fast transfers.
     $active = false;
     $multi = $context->getMultiHandle();
     do {
         do {
             $mrc = curl_multi_exec($multi, $active);
         } while ($mrc === CURLM_CALL_MULTI_PERFORM);
         if ($mrc != CURLM_OK) {
             self::throwMultiError($mrc);
         }
         $this->processMessages($context);
         if ($active && curl_multi_select($multi, $this->selectTimeout) === -1) {
             // Perform a usleep if a select returns -1.
             // See: https://bugs.php.net/bug.php?id=61141
             usleep(250);
         }
     } while ($context->isActive() || $active);
     $this->releaseMultiHandle($multi);
 }