PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/services/scraper/device/wurfl/admin/stats.php

https://github.com/bcmoney/OpenRecommender
PHP | 214 lines | 187 code | 9 blank | 18 comment | 16 complexity | c448679d8365da68e9a13aac05a6c5ff MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, MIT, LGPL-2.1, GPL-2.0, AGPL-3.0
  1. <?php
  2. /**
  3. * Copyright (c) 2011 ScientiaMobile, Inc.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * Refer to the COPYING file distributed with this package.
  11. *
  12. * @package WURFL_Admin
  13. * @copyright ScientiaMobile, Inc.
  14. * @author Steve Kamerman <steve AT scientiamobile.com>
  15. * @license GNU Affero General Public License
  16. * @version $id$
  17. */
  18. require_once realpath(dirname(__FILE__).'/../TeraWurfl.php');
  19. $tw = new TeraWurfl();
  20. $db = $tw->db;
  21. $missing_tables = false;
  22. if($db->connected === true){
  23. $required_tables = array(TeraWurflConfig::$TABLE_PREFIX.'Cache',TeraWurflConfig::$TABLE_PREFIX.'Index',TeraWurflConfig::$TABLE_PREFIX.'Merge');
  24. $tables = $db->getTableList();
  25. // See what tables are in the DB
  26. //die(var_export($tables,true));
  27. foreach($required_tables as $req_table){
  28. if(!in_array($req_table,$tables)){
  29. $missing_tables = true;
  30. }
  31. }
  32. }
  33. $mergestats = $db->getTableStats(TeraWurflConfig::$TABLE_PREFIX.'Merge');
  34. $indexstats = $db->getTableStats(TeraWurflConfig::$TABLE_PREFIX.'Index');
  35. $cachestats = $db->getTableStats(TeraWurflConfig::$TABLE_PREFIX.'Cache');
  36. $matcherList = $db->getMatcherTableList();
  37. $matchers = array();
  38. foreach($matcherList as $name){
  39. $matchers[] = array('name'=>$name,'stats'=>$db->getTableStats($name));
  40. }
  41. $logfile = $tw->rootdir.TeraWurflConfig::$DATADIR.TeraWurflConfig::$LOG_FILE;
  42. if(!is_readable($logfile) || filesize($logfile) < 5){
  43. $lastloglines = "Empty";
  44. }else{
  45. $logarr = file($logfile);
  46. $loglines = 30;
  47. if(count($logarr)<$loglines)$loglines=count($logarr);
  48. $end = count($logarr)-1;
  49. $lastloglines = '';
  50. for($i=$end;$i>=($end-$loglines);$i--){
  51. $lastloglines .= @htmlspecialchars($logarr[$i])."<br />";
  52. }
  53. }
  54. ?>
  55. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  56. <html xmlns="http://www.w3.org/1999/xhtml">
  57. <head>
  58. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  59. <title>Tera-WURFL Administration</title>
  60. <link href="style.css" rel="stylesheet" type="text/css" /></head>
  61. <body>
  62. <table width="800">
  63. <tr><td>
  64. <div align="center" class="titlediv">
  65. <p> Tera-WURFL <?php echo $tw->release_version; ?> Administration<br />
  66. <span class="version">Loaded WURFL: <?php echo $tw->getSetting(TeraWurfl::$SETTING_WURFL_VERSION); ?></span></p>
  67. </div>
  68. </td></tr><tr><td>
  69. <h3><br />
  70. <a href="index.php">&lt;&lt; Back to main page </a></h3>
  71. <table width="800" border="0" cellspacing="0" cellpadding="0">
  72. <tr>
  73. <th scope="col">Database Table </th>
  74. <th scope="col">Statistics</th>
  75. </tr>
  76. <tr>
  77. <td width="145" class="darkrow">MERGE<br />
  78. <span class="setting"><?php echo TeraWurflConfig::$TABLE_PREFIX.'Merge'?></span></td>
  79. <td width="655" class="darkrow">Rows: <span class="setting"><?php echo $mergestats['rows']?></span><br />
  80. Actual Devices: <span class="setting"><?php echo $mergestats['actual_devices']?></span> <br />
  81. Table Size: <span class="setting"><?php echo WurflSupport::formatBytes($mergestats['bytesize'])?></span><br />
  82. Purpose:<br />
  83. <span class="setting">The MERGE table holds all the data from the WURFL file, whether it be local, remote or remote CVS, whenever a new WURFL is loaded, it is loaded into this table first, then it is filtered through all the UserAgentMatchers and split into many different tables specific to each matching technique. This MERGE table is retained for a last chance lookup if the UserAgentMatchers and INDEX table are unable to provide a conclusive match.</span></td>
  84. </tr>
  85. <?php if(!empty($indexstats)){ ?>
  86. <tr>
  87. <td class="lightrow">INDEX <br />
  88. <span class="setting"><?php echo TeraWurflConfig::$TABLE_PREFIX.'Index'?></span></td>
  89. <td class="lightrow">Rows: <span class="setting"><?php echo $indexstats['rows']?></span><br />
  90. Table Size: <span class="setting"><?php echo WurflSupport::formatBytes($indexstats['bytesize'])?></span><br />
  91. Purpose:<br />
  92. <span class="setting">The INDEX table acts as a lookup table for WURFL IDs and their respective UserAgentMatchers. </span></td>
  93. </tr>
  94. <?php } ?>
  95. <tr>
  96. <td class="darkrow">CACHE <br />
  97. <span class="setting"><?php echo TeraWurflConfig::$TABLE_PREFIX.'Cache'?></span></td>
  98. <td class="darkrow">Rows: <span class="setting"><?php echo $cachestats['rows']?></span><br />
  99. Table Size: <span class="setting"><?php echo WurflSupport::formatBytes($cachestats['bytesize'])?></span><br />
  100. Purpose:<br />
  101. <span class="setting">The CACHE table stores unique user agents and the complete capabilities and device root that were determined when the device was first identified. <strong>Unlike version 1.x</strong>, the CACHE table stores every device that is detected <strong>permanently</strong>. When the device database is updated, the cached devices are also redetected and recached. This behavior is configurable.</span></td>
  102. </tr>
  103. <?php if(!empty($matchers)){ ?>
  104. <tr>
  105. <td class="lightrow" style="vertical-align:top;">User Agent Matchers<br/>
  106. Purpose:<br />
  107. <span class="setting">The User Agent Matchers store similar user agents. Tera-WURFL sorts all the devices into the most appropriate UserAgentMatcher table to make lookups faster and perform different matching hueristics on certain groups of devices.</span></td><td>
  108. <table>
  109. <?php
  110. $i=0;
  111. foreach($matchers as $matcher){
  112. $class = ($i % 2 == 0)? "lightrow": "darkrow";
  113. ?>
  114. <tr><td class="<?php echo $class;?>">UserAgentMatcher: <span class="setting"><?php echo $matcher['name']?></span><br />
  115. Rows: <span class="setting"><?php echo $matcher['stats']['rows']?></span><br />
  116. Table Size: <span class="setting"><?php echo WurflSupport::formatBytes($matcher['stats']['bytesize'])?></span></td></tr>
  117. <?php
  118. $i++;
  119. }
  120. ?></table></td>
  121. </tr>
  122. <?php } ?>
  123. </table>
  124. <p><br/>
  125. <br/>
  126. </p>
  127. <table width="800" border="0" cellpadding="0" cellspacing="0">
  128. <tr>
  129. <th scope="col">Tera-WURFL Settings</th>
  130. </tr>
  131. <tr><td>Installation Directory: <span class="setting"><?php echo dirname(dirname(__FILE__)); ?></span></td></tr>
  132. <tr>
  133. <td class="lightrow"><p>-- Database options --<br/>
  134. DB_HOST <span class="setting">
  135. <?php echo TeraWurflConfig::$DB_HOST?>
  136. </span>, database server hostname or IP<br />
  137. DB_USER <span class="setting">
  138. <?php echo TeraWurflConfig::$DB_USER?>
  139. </span>, database username (needs SELECT,INSERT,DELETE,DROP,CREATE)<br />
  140. DB_PASS <span class="setting">********</span>, database password<br />
  141. DB_SCHEMA <span class="setting">
  142. <?php echo TeraWurflConfig::$DB_SCHEMA?>
  143. </span>, database schema (database name)<br />
  144. DB_CONNECTOR <span class="setting">
  145. <?php echo TeraWurflConfig::$DB_CONNECTOR?>
  146. </span>, database type (MySQL4, MySQL5, MSSQL2005, etc...);<br />
  147. TABLE_PREFIX <span class="setting">
  148. <?php echo TeraWurflConfig::$TABLE_PREFIX?>
  149. </span>, prefix to be used for all table names<br />
  150. <br />
  151. -- General options --<br />
  152. WURFL_DL_URL <span class="setting">
  153. <?php echo TeraWurflConfig::$WURFL_DL_URL?>
  154. </span>, full URL to the current WURFL<br />
  155. WURFL_CVS_URL <span class="setting">
  156. <?php echo TeraWurflConfig::$WURFL_CVS_URL?>
  157. </span>, full URL to development (CVS) WURFL<br />
  158. DATADIR <span class="setting">
  159. <?php echo TeraWurflConfig::$DATADIR?>
  160. </span>, where all data is stored (wurfl.xml, temp files, logs)<br />
  161. CACHE_ENABLE <span class="setting"><?php echo WurflSupport::showBool(TeraWurflConfig::$CACHE_ENABLE)?></span>, enables or disables the cache <br />
  162. PATCH_ENABLE <span class="setting">
  163. <?php echo WurflSupport::showBool(TeraWurflConfig::$PATCH_ENABLE)?>
  164. </span>, enables or disables the patch<br />
  165. PATCH_FILE <span class="setting">
  166. <?php echo TeraWurflConfig::$PATCH_FILE?>
  167. </span>, optional patch file for WURFL. To use more than one, separate them with semicolons<br />
  168. WURFL_FILE <span class="setting">
  169. <?php echo TeraWurflConfig::$WURFL_FILE?>
  170. </span>, path and filename of wurfl.xml<br />
  171. WURFL_LOG_FILE <span class="setting">
  172. <?php echo TeraWurflConfig::$LOG_FILE?>
  173. </span>, defines full path and filename for logging<br />
  174. LOG_LEVEL <span class="setting">
  175. <?php echo WurflSupport::showLogLevel(TeraWurflConfig::$LOG_LEVEL)?>
  176. </span>, desired logging level. Use the same constants as for PHP logging<br />
  177. OVERRIDE_MEMORY_LIMIT <span class="setting">
  178. <?php echo WurflSupport::showBool(TeraWurflConfig::$OVERRIDE_MEMORY_LIMIT)?>
  179. </span>, override PHP's default memory limit<br />
  180. MEMORY_LIMIT <span class="setting">
  181. <?php echo TeraWurflConfig::$MEMORY_LIMIT?>
  182. </span>, the amount of memory to allocate to PHP if OVERRIDE_MEMORY_LIMIT is enabled<br />
  183. SIMPLE_DESKTOP_ENGINE_ENABLE <span class="setting">
  184. <?php echo WurflSupport::showBool(TeraWurflConfig::$SIMPLE_DESKTOP_ENGINE_ENABLE)?>
  185. </span>, enable the SimpleDesktop Detection Engine to increase performance<br />
  186. CAPABILITY_FILTER:
  187. <?php echo "<pre class=\"setting\">".var_export(TeraWurflConfig::$CAPABILITY_FILTER,true)."</pre>";?>
  188. the capability filter that is used to determine which capabilities are available<br />
  189. </p>
  190. </td>
  191. </tr>
  192. </table>
  193. <p>&nbsp;</p>
  194. <table width="800" border="0" cellpadding="0" cellspacing="0">
  195. <tr>
  196. <th scope="col">Log File (last 30 lines) </th>
  197. </tr>
  198. <tr>
  199. <td class="lightrow"><div class="logfile"><?php echo $lastloglines?></div>
  200. <br/></td>
  201. </tr>
  202. </table> <p>&nbsp; </p></td>
  203. </tr></table>
  204. </body>
  205. </html>