if (!file_exists($configFile)) { die('Config file not found'); } // Ensure data file present if (!file_exists($dataFile)) { die('Data file not found'); } include $configFile; if (@$hdconfig['username'] == "your_api_username") { die('Please configure your username, secret and site_id'); } // Create a new detection object $hd = new HandsetDetection\HD4($configFile); // fetch the archive if it does not exist if (!file_exists('/tmp/hd40store/user-agent0.json')) { $hd->deviceFetchArchive(); } class FileException extends Exception { } class Benchmark { private $file; private $time_start; private $time; private $headers; var $count = 0; private $verbose = true; function __construct($filename) { try {
// Note : We use the ipaddress to get the geoip location. echo "<h1>Simple Detection - Passing a different ip address</h1><p>"; $hd->setDetectVar('ipaddress', '64.34.165.180'); if ($hd->deviceDetect(array('options' => 'geoip,hd_specs'))) { $tmp = $hd->getReply(); print_r($tmp); } else { print $hd->getError(); } echo "</p>"; // Ultimate customers can also download the ultimate database. // Note - Increase default timeout echo "<h1>Archive Information</h1><p>"; $hd->setTimeout(500); $time_start = _getmicrotime(); if ($hd->deviceFetchArchive()) { $data = $hd->getRawReply(); echo "Downloaded " . strlen($data) . " bytes"; } else { print $hd->getError(); print $hd->getRawReply(); print "\n"; } $time_elapsed = _getmicrotime() - $time_start; echo "<br/>Time elapsed " . $time_elapsed . "ms"; echo "</p>"; function _getmicrotime() { list($usec, $sec) = explode(" ", microtime()); return (double) $usec + (double) $sec; }
/** * Fetch Archive Test * @group ultimate **/ function test_fetchArchive() { // Note : request storage dir to be created if it does not exist. (with TRUE as 2nd param) $hd = new HandsetDetection\HD4($this->ultimateConfig, true); $result = $hd->deviceFetchArchive(); $this->assertTrue($result); $data = $hd->getRawReply(); echo "Downloaded " . strlen($data) . " bytes"; $this->assertGreaterThan(19000000, strlen($data)); // Filesize greater than 19Mb (currently 21Mb). }
/** * Fetch Archive Test * @group ultimate **/ function test_fetchArchive() { $hd = new HandsetDetection\HD4($this->ultimateConfig); $hd->setTimeout(500); $store = HandsetDetection\HDStore::getInstance(); $store->purge(); $result = $hd->deviceFetchArchive(); $data = $hd->getRawReply(); $size = strlen($data); echo "Downloaded {$size} bytes "; if (!$result) { $data = $hd->getReply(); print_r($data); } if ($size < 1000) { $this->markTestSkipped($data); } else { $this->assertTrue($result); $this->assertGreaterThan(19000000, strlen($data)); // Filesize greater than 19Mb (currently 28Mb). } }