private function HandleCallQuota()
    {
        if ($this->_quota_LastCall == NULL) {
            $this->_quota_LastCall = new \DateTime();
            $this->_quota_LastCall->setTimestamp(0);
        }

        $now = new \DateTime();
        $secsFromLastCall = $now->getTimestamp() - $this->_quota_LastCall->getTimestamp();

        if ($secsFromLastCall > self::QUOTA_WAIT_SECS_AFTER_EXCEEDED) {
            // time-frame is ok
            $this->_quota_CallCounter = 0;
        } else {
            // time-frame too short
            $this->_quota_CallCounter++;
            if ($this->_quota_CallCounter >= self::QUOTA_MAX_CALLS) {
                // counter exceeded: wait a bit..
                sleep(self::QUOTA_WAIT_SECS_AFTER_EXCEEDED);
                $this->_quota_CallCounter = 0;
            }
        }

        $this->_quota_LastCall = new \DateTime("now");
    }
private function HandleCallQuota()
    {
        if ($this->_quota_LastCall == NULL) {
            $this->_quota_LastCall = new \DateTime();
            $this->_quota_LastCall->setTimestamp(0);
        }

        $now = new \DateTime();
        $secsFromLastCall = $now->getTimestamp() - $this->_quota_LastCall->getTimestamp();

        if ($secsFromLastCall > self::QUOTA_WAIT_SECS_AFTER_EXCEEDED) {
            // time-frame is ok
            $this->_quota_CallCounter = 0;
        } else {
            // time-frame too short
            $this->_quota_CallCounter++;
            if ($this->_quota_CallCounter >= self::QUOTA_MAX_CALLS) {
                // counter exceeded: wait a bit..
                sleep(self::QUOTA_WAIT_SECS_AFTER_EXCEEDED);
                $this->_quota_CallCounter = 0;
            }
        }

        $this->_quota_LastCall = new \DateTime("now");
    }
private function HandleCallQuota ( ) { if ( $ this -> _quota_LastCall == NULL ) { $ this -> _quota_LastCall = new \ DateTime ( ) ; $ this -> _quota_LastCall -> setTimestamp ( 0 ) ; } $ now = new \ DateTime ( ) ; $ secsFromLastCall = $ now -> getTimestamp ( ) - $ this -> _quota_LastCall -> getTimestamp ( ) ; if ( $ secsFromLastCall > self :: QUOTA_WAIT_SECS_AFTER_EXCEEDED ) { // time-frame is ok $ this -> _quota_CallCounter = 0 ; } else { // time-frame too short $ this -> _quota_CallCounter ++ ; if ( $ this -> _quota_CallCounter >= self :: QUOTA_MAX_CALLS ) { // counter exceeded: wait a bit.. sleep ( self :: QUOTA_WAIT_SECS_AFTER_EXCEEDED ) ; $ this -> _quota_CallCounter = 0 ; } } $ this -> _quota_LastCall = new \ DateTime ( "now" ) ; }
To avoid unneeded traffic to the server, slow-down a bit.
Server checks this anyway, so to preserve the client's traffic, avoid excessive usage.
To avoid unneeded traffic to the server slow - down a bit . Server checks this anyway so to preserve the client s traffic avoid excessive usage .