Exemplo n.º 1
0
 public function testCreateNumber()
 {
     $number = FibonacciFactory::number();
     $this->assertSame(0, $number->getCurrent());
     $this->assertSame(1, $number->getNext()->getCurrent());
     $this->assertSame(1, $number->getNext()->getNext()->getCurrent());
     $this->assertSame(2, $number->getNext()->getNext()->getNext()->getCurrent());
     $this->assertSame(3, $number->getNext()->getNext()->getNext()->getNext()->getCurrent());
     $this->assertSame(5, $number->getNext()->getNext()->getNext()->getNext()->getNext()->getCurrent());
 }
 private static function pollWait()
 {
     $parts = parse_url(static::$endpoint);
     foreach (FibonacciFactory::sequence(50000, 10000, 10) as $offset => $sleepTime) {
         usleep($sleepTime);
         $socket = @fsockopen($parts['host'], $parts['port'], $errorNumber, $errorString, 1);
         if ($socket !== false) {
             fclose($socket);
             return;
         }
     }
 }
Exemplo n.º 3
0
 private function pollWait()
 {
     foreach (FibonacciFactory::sequence(50000, 10000) as $sleepTime) {
         try {
             usleep($sleepTime);
             $this->getClient()->head('/_me')->send();
             break;
         } catch (CurlException $e) {
             continue;
         }
     }
 }