コード例 #1
0
 public function testCanCloseAll()
 {
     $m = curl_multi_init();
     $b = new puzzle_adapter_curl_BatchContext($m, true);
     $h = curl_init();
     $t = new puzzle_adapter_Transaction(new puzzle_Client(), new puzzle_message_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);
 }
コード例 #2
0
ファイル: MultiAdapter.php プロジェクト: puzzlehttp/puzzle
 private function perform(puzzle_adapter_curl_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);
 }