now() public static method

Return timestamp for now.
public static now ( ) : float
return float
Beispiel #1
0
 /**
  * @param ChannelInterface $channel
  * @param string $name
  * @param string|ProtocolInterface $message
  * @param mixed[] $params
  */
 public function __construct($channel, $name, $message, $params = [])
 {
     $this->channel = $channel;
     $this->name = $name;
     $this->message = $message instanceof ProtocolInterface ? $message : $this->channel->createProtocol($message);
     $this->params = ['timeout' => isset($params['timeout']) ? $params['timeout'] : 2.0, 'retriesLimit' => isset($params['retriesLimit']) ? $params['retriesLimit'] : 10, 'retriesInterval' => isset($params['retriesInterval']) ? $params['retriesInterval'] : 0.25];
     $this->counter = 1;
     $this->message->setTimestamp(TimeSupport::now() + ($this->params['retriesInterval'] + $this->params['timeout']) * 1000.0 * $this->params['retriesLimit'], true);
 }
 /**
  *
  */
 public function testApiCreateRequest_AddsNowToPositiveTimeout()
 {
     $obj = $this->createRequestRecordStorage();
     $pid = 'pid';
     $timeout = 1.0;
     $req = $this->callProtectedMethod($obj, 'createRequest', [$pid, null, null, null, $timeout]);
     $timeout = $timeout * 1000 + TimeSupport::now();
     $this->assertGreaterThan($timeout - 1000, $req->getTimeout());
     $this->assertLessThanOrEqual($timeout, $req->getTimeout());
 }
 /**
  * @return float
  */
 protected function getTime()
 {
     return TimeSupport::now();
 }
 /**
  * Cancel overdue Requests.
  */
 protected function expireRequests()
 {
     $now = TimeSupport::now();
     $expiredReqs = [];
     foreach ($this->reqs as $pid => $request) {
         if ($now >= $request->getTimeout()) {
             $expiredReqs[] = $request;
         }
     }
     foreach ($expiredReqs as $request) {
         unset($this->reqs[$request->getPid()]);
     }
     foreach ($expiredReqs as $request) {
         $request->cancel(new ThrowableProxy(new TimeoutException("RequestRecord has expired.")));
     }
 }
 /**
  *
  */
 public function testApiExpireResponses_ExpiresResponsesWhichTimeoutIsLessThanTimeNow()
 {
     $obj = $this->createResponseRecordStorage();
     $now = TimeSupport::now();
     $rep1 = new ResponseRecord($pid1 = 'pid1', $alias1 = 'alias1', $now + 1000000.0);
     $rep2 = new ResponseRecord($pid2 = 'pid2', $alias2 = 'alias2', $now);
     $this->callProtectedMethod($obj, 'addResponse', [$pid1, $rep1]);
     $this->callProtectedMethod($obj, 'addResponse', [$pid2, $rep2]);
     $this->callProtectedMethod($obj, 'resolveOrRejectResponse', [$pid2, new Exception()]);
     $this->assertTrue(array_key_exists($pid2, $this->getProtectedProperty($obj, 'handledReps')));
     $reps = $this->getProtectedProperty($obj, 'handledReps');
     $this->setProtectedProperty($reps[$pid2], 'timeout', $now - 1000);
     $this->callProtectedMethod($obj, 'expireResponses');
     $this->assertFalse(array_key_exists('pid', $this->getProtectedProperty($obj, 'handledReps')));
 }
 /**
  * Expire unhandled ResponseRecords.
  */
 protected function expireResponses()
 {
     $now = TimeSupport::now();
     $expiredReps = [];
     foreach ($this->handledReps as $pid => $response) {
         if ($now >= $response->timeout) {
             $expiredReps[] = $pid;
         }
     }
     foreach ($expiredReps as $pid) {
         unset($this->handledReps[$pid]);
     }
 }