示例#1
0
 /**
  * @name throttle
  *
  * Throttle API calls using the $queryLimit class property
  **
  * @return null
  */
 private static function throttle()
 {
     self::$queryCount++;
     if (self::$queryWindowStartTime === null) {
         self::$queryWindowStartTime = new DateTime();
     }
     if (self::$queryCount > self::$queryLimit) {
         $now = new DateTime();
         $diffSec = $now->getTimestamp() - self::$queryWindowStartTime->getTimestamp();
         // If we've exceeded the query count, and we still are within the query window, then wait.
         if ($diffSec < self::$queryWindowSecs) {
             sleep(self::$queryWindowSecs - $diffSec + 1);
         }
         // Then, once we've waited, if necessary, we'll assume that we're beyond the query window, so we'll start our throttling over.
         self::$queryWindowStartTime = new DateTime();
         self::$queryCount = 1;
     }
 }
示例#2
0
<?php

/**
 *
 * PHP-HaloAPI
 * v 1.0.2-beta
 *
 * Example page
 *
 * Author: Gaspard Rosay
 * Date: 04.11.15
 * WTPFL Licence
 *
 */
require_once 'haloapi.class.php';
$aPlayerNames = array('BananasSplitter', 'SatanicGeek');
// Creating an array of player.
$sApiKey = "****";
$oHaloApi = new haloapi($sApiKey, $aPlayerNames);
// Initializing the class
$sEmblemUrl = $oHaloApi->getEmblem(512);
// Get emblem img - size of 512
echo "<img src='{$sEmblemUrl}' />";
$oJson = $oHaloApi->getServiceRecords("campaign");
// Get service records for campaign
echo "<pre>" . print_r($oJson, 1) . "</pre>";