Gets all expired clients based on a timeout in microseconds.

@param int $timeout

@return \AlphaRPC\Manager\ClientHandler\Client[]
196664
public function getExpired($timeout)
    {
        $expired = array();
        $timeoutAt = microtime(true) - ($timeout / 1000);
        foreach ($this->clients as $client) {
            if ($client->getTime() > $timeoutAt) {
                // Clients are ordered by time.
                break;
            }
            $expired[] = $client;
        }

        return $expired;
    }
827146
public function iterate($timeout)
    {

        // call parent method and sleep for the default timeout
        parent::iterate($timeout);

        // iterate over the timer tasks that has to be executed
        foreach ($this->tasksToExecute as $taskId => $timerTaskWrapper) {
            // this should never happen
            if (!$timerTaskWrapper instanceof \stdClass) {
                // log an error message because we task wrapper has wrong type
                \error(sprintf('Timer-Task-Wrapper %s has wrong type %s', $taskId, get_class($timerTaskWrapper)));
                // we didn't foud a timer task ignore this
                continue;
            }

            // query if the task has to be executed now
            if ($timerTaskWrapper->executeAt < microtime(true)) {
                // load the timer task wrapper we want to execute
                if ($pk = $this->scheduledTimers[$timerId = $timerTaskWrapper->timerId]) {
                    // load the timer service registry
                    $timerServiceRegistry = $this->getApplication()->search(TimerServiceContextInterface::IDENTIFIER);

                    // lookup the timer from the timer service
                    $timer = $timerServiceRegistry->lookup($pk)->getTimers()->get($timerId);

                    // create and execute the timer task
                    $this->timerTasks[$taskId] = $timer->getTimerTask($this->getApplication());

                    // remove the key from the list of tasks to be executed
                    unset($this->tasksToExecute[$taskId]);

                } else {
                    // log an error message because we can't find the timer instance
                    \error(sprintf('Can\'t find timer %s to create timer task %s', $timerTaskWrapper->timerId, $taskId));
                }
            }
        }

        // collect the garbage (finished timer task jobs)
        $this->collectGarbage();

        // profile the size of the timer tasks to be executed
        if ($this->profileLogger) {
            $this->profileLogger->debug(
                sprintf('Processed timer service executor, executing %d timer tasks', sizeof($this->tasksToExecute))
            );
        }
    }
821544
public function setTimeout($timeout)
    {
        $this->params['timeout'] = (int) $timeout;
        $this->buffer->setParam('timeout', (int) $timeout);

        return $this;
    }
35738
public function sets(array $keyArray, $timeout) {
		if (!is_array($keyArray)) {
			throw new Exception('Call  ' . __FUNCTION__ . ' method  parameter  Error !');
		}
		$retRes = $this->driver->mset($keyArray);
		if ($timeout <= 0) {
			return $retRes;
		}
		foreach ($keyArray as $key => $value) {
			$this->driver->expire($key, $timeout);
		}
		return true;
	}
553007
public function findAllExpired()
    {
        $expiredBlacklistedTokens = $this->model->where('expiry', '<', Carbon::now())->get();

        return $expiredBlacklistedTokens->toArray();
    }
163573
public function handleExpiration() : array
    {
        $deleted   = [];
        $cacheKeys = $this->cache->keys();

        foreach ($cacheKeys as $key) {
            $fileMeta = $this->cache->get($key, true);

            if ( ! $this->isExpired($fileMeta)) {
                continue;
            }

            if ( ! $this->cache->delete($key)) {
                continue;
            }

            if (is_writable($fileMeta['file_path'])) {
                unlink($fileMeta['file_path']);
            }

            $deleted[] = $fileMeta;
        }

        return $deleted;
    }
311425
public static function get_expired_requests($userid = 0) {
        global $DB;

        $expiryseconds = get_config('tool_dataprivacy', 'privacyrequestexpiry');
        $expirytime = strtotime("-{$expiryseconds} second");
        $table = self::TABLE;
        $sqlwhere = 'type = :export_type AND status = :completestatus AND timemodified <= :expirytime';
        $params = array(
            'export_type' => api::DATAREQUEST_TYPE_EXPORT,
            'completestatus' => api::DATAREQUEST_STATUS_DOWNLOAD_READY,
            'expirytime' => $expirytime,
        );
        $sort = 'id';
        $fields = 'id, userid';

        // Filter by user ID if specified.
        if ($userid > 0) {
            $sqlwhere .= ' AND (userid = :userid OR requestedby = :requestedby)';
            $params['userid'] = $userid;
            $params['requestedby'] = $userid;
        }

        return $DB->get_records_select_menu($table, $sqlwhere, $params, $sort, $fields, 0, 2000);
    }
905994
public function getExpiredCodes($limit = 100)
    {
        $query = $this->createQueryBuilder('p')
            ->select('p')
            ->andWhere('p.expire < :expire')
            ->setParameter('expire', new \DateTime())
            ->orderBy('p.expire', 'asc')
            ->setMaxResults($limit)
            ->getQuery();

        return $query->getResult();
    }
1094715
public function receive($timeout = 0)
    {
        $startAt = microtime(true);

        while (true) {
            $message = $this->receiveMessage();

            if ($message) {
                return $message;
            }

            if ($timeout && (microtime(true) - $startAt) >= $timeout) {
                return;
            }

            usleep($this->pollingInterval);

            if ($timeout && (microtime(true) - $startAt) >= $timeout) {
                return;
            }
        }
    }
73935
public function iterate($timeout)
    {

        // call parent method and sleep for the default timeout
        parent::iterate($timeout);

        // create the requested timer instance
        $this->synchronized(function ($self) {

            // create the calendar timer, only if we're NOT dispatched
            if ($self->dispatched === false) {
                $self->timer = CalendarTimer::builder()
                    ->setAutoTimer($self->timeoutMethod != null)
                    ->setScheduleExprSecond($self->schedule->getSecond())
                    ->setScheduleExprMinute($self->schedule->getMinute())
                    ->setScheduleExprHour($self->schedule->getHour())
                    ->setScheduleExprDayOfWeek($self->schedule->getDayOfWeek())
                    ->setScheduleExprDayOfMonth($self->schedule->getDayOfMonth())
                    ->setScheduleExprMonth($self->schedule->getMonth())
                    ->setScheduleExprYear($self->schedule->getYear())
                    ->setScheduleExprStartDate($self->schedule->getStart())
                    ->setScheduleExprEndDate($self->schedule->getEnd())
                    ->setScheduleExprTimezone($self->schedule->getTimezone())
                    ->setTimeoutMethod($self->timeoutMethod)
                    ->setTimerState(TimerState::CREATED)
                    ->setId(Uuid::uuid4()->__toString())
                    ->setPersistent($self->persistent)
                    ->setTimedObjectId($self->timerService->getTimedObjectInvoker()->getTimedObjectId())
                    ->setInfo($self->info)
                    ->setNewTimer(true)
                    ->build($self->timerService);

                // we're dispatched now
                $self->dispatched = true;
            }

        }, $this);

        // profile the size of the sessions
        if ($this->profileLogger) {
            $this->profileLogger->debug(
                sprintf('Size of session pool is: %d', sizeof($this->sessionPool))
            );
        }
    }
344133
public function expire($key, $timeout) {
        try {
            return $this->getRedis()->pexpire($key, $timeout);
        } catch (RedisException $ex) {
            throw new ConnectException();
        }
    }
115638
public function setTimeout($timeout) {
            $this->timeout = $timeout;
            $this->process->setTimeout($this->timeout);
            return $this;
        }
69480
protected function _receive($timeout = null)
    {
        if (!is_resource($this->_socket)) {
            /**
             * @see Zend_Mail_Protocol_Exception
             */
            // require_once 'Zend/Mail/Protocol/Exception.php';
            throw new Zend_Mail_Protocol_Exception('No connection has been established to ' . $this->_host);
        }

        // Adapters may wish to supply per-commend timeouts according to appropriate RFC
        if ($timeout !== null) {
            $this->_setStreamTimeout($timeout);
        }

        // Retrieve response
        $reponse = fgets($this->_socket, 1024);

        // Save request to internal log
        $this->_addLog($reponse);

        // Check meta data to ensure connection is still valid
        $info = stream_get_meta_data($this->_socket);

        if (!empty($info['timed_out'])) {
            /**
             * @see Zend_Mail_Protocol_Exception
             */
            // require_once 'Zend/Mail/Protocol/Exception.php';
            throw new Zend_Mail_Protocol_Exception($this->_host . ' has timed out');
        }

        if ($reponse === false) {
            /**
             * @see Zend_Mail_Protocol_Exception
             */
            // require_once 'Zend/Mail/Protocol/Exception.php';
            throw new Zend_Mail_Protocol_Exception('Could not read from ' . $this->_host);
        }

        return $reponse;
    }
640672
public function hasEvents($timeout = 0)
    {
        $poll = new ZMQPoll();
        $poll->add($this, ZMQ::POLL_IN);
        $read = $write = array();
        $events = $poll->poll($read, $write, $timeout);
        if ($events > 0) {
            return true;
        }

        return false;
    }
514415
public function setReadTimeout(int $timeout)
	{
		if ($timeout < -1) {
			throw new RedisException('Timeout values less than -1 are not accepted.');
		}
		$this->readTimeout = $timeout;
		if ($this->connected) {
			// supported in phpredis 2.2.3
			// a timeout value of -1 means reads will not timeout
			$timeout = $timeout === 0 ? -1 : $timeout;
			$this->redis->setOption(\Redis::OPT_READ_TIMEOUT, $timeout);
		}

		return $this;
	}
457324
public function connect($timeout = 0.5)
    {
        if (extension_loaded('swoole'))
        {
            $type = preg_match('/^[0-9\.]+$/', $this->host) ? SWOOLE_SOCK_TCP : SWOOLE_SOCK_UNIX_STREAM;
            if ($this->ssl)
            {
                $type |= SWOOLE_SSL;
            }
            $this->socket = new \swoole_client($type);
            if ($this->ssl_key_file)
            {
                $this->socket->set(array(
                    'ssl_key_file' => $this->ssl_key_file,
                    'ssl_cert_file' => $this->ssl_cert_file
                ));
            }
        }
        else
        {
            $this->socket = new TCP;
        }
        //建立连接
        if (!$this->socket->connect($this->host, $this->port, $timeout))
        {
            return false;
        }
        $this->connected = true;
        //WebSocket握手
        if ($this->socket->send($this->createHeader()) === false)
        {
            return false;
        }
        $headerBuffer = '';
        while(true)
        {
            $_tmp = $this->socket->recv();
            if ($_tmp)
            {
                $headerBuffer .= $_tmp;
                $offset = stripos($headerBuffer,"\r\n\r\n");
                if ($offset === false) {
                    continue;
                }
                $header = substr($headerBuffer, 0, $offset+4);
                $this->buffer = substr($headerBuffer, $offset+4);
            }
            else
            {
                return false;
            }
            return $this->doHandShake($header);
        }
        return false;
    }
1007665
public function setTimeout($timeout) {
        $this->_timeout = (int) $timeout;
        if ( ! is_null($this->_varnishConn)) {
            stream_set_timeout($this->_varnishConn, $this->_timeout);
        }
        return $this;
    }