public function testReturnsPendingAsIteratorTypeObject() { $t1 = new Transaction(new Client(), new Request('GET', 'http://t.com')); $t2 = new Transaction(new Client(), new Request('GET', 'http://t.com')); $t3 = new Transaction(new Client(), new Request('GET', 'http://t.com')); $iter = new \ArrayIterator([$t1, $t2, $t3]); $b = new BatchContext('foo', false, $iter); $this->assertTrue($b->hasPending()); $this->assertSame($t1, $b->nextPending()); $this->assertTrue($b->hasPending()); $this->assertSame($t2, $b->nextPending()); $this->assertTrue($b->hasPending()); $this->assertSame($t3, $b->nextPending()); $this->assertFalse($b->hasPending()); $this->assertNull($b->nextPending()); }
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 { while (($mrc = curl_multi_exec($multi, $active)) == CURLM_CALL_MULTI_PERFORM) { } if ($mrc != CURLM_OK && $mrc != CURLM_CALL_MULTI_PERFORM) { self::throwMultiError($mrc); } // Need to check if there are pending transactions before processing // them so that we don't bail from the loop too early. $pending = $context->hasPending(); $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 ($active || $pending); $this->releaseMultiHandle($multi); }