tera_wurfl
[ class tree: tera_wurfl ] [ index: tera_wurfl ] [ all elements ]

Source for file stats.php

Documentation is available at stats.php

  1. <?php
  2. require_once('../tera_wurfl_config.php');
  3. require_once(WURFL_PARSER_FILE);
  4. // connect to DB
  5. $dbcon mysql_connect(DB_HOST,DB_USER,DB_PASSor die("Could not connect to MySQL Server (".DB_HOST."): ".mysql_error());
  6. // select DB
  7. mysql_select_db(DB_SCHEMA,$dbconor die("Connected to MySQL Server but could not select database (".DB_SCHEMA."): ".mysql_error($dbcon));
  8. // check tables
  9. $tablesres mysql_query("SHOW TABLES");
  10. $required_tables array(DB_DEVICE_TABLE,DB_PATCH_TABLE,DB_HYBRID_TABLE);
  11. $tables array();
  12. while($table mysql_fetch_row($tablesres))$tables[]=$table[0];
  13. foreach($required_tables as $req_table){
  14.     if(!in_array($req_table,$tables)){
  15.         echo "Required table '$req_tablewas missing in database (".print_r($tables,true)."), creating...<br />";
  16.         emptyWurflDevTable($req_table);
  17.     }
  18. }
  19. function showBool($var){
  20.     if($var === true)return("true");
  21.     if($var === false)return("false");
  22.     return($var);
  23. }
  24. function showLogLevel($num){
  25.     $log_arr array("LOG_EMERG","LOG_ALERT","LOG_CRIT","LOG_ERR","LOG_WARNING","LOG_NOTICE","LOG_INFO","LOG_DEBUG");
  26.     return($log_arr[$num]);
  27. }
  28. function tableStats($table){
  29.     $stats array();
  30.     $fields array();
  31.     $fieldnames array();
  32.     $fieldsres mysql_query("SHOW COLUMNS FROM ".$table);
  33.     while($row mysql_fetch_assoc($fieldsres)){
  34.         $fields['CHAR_LENGTH(`'.$row['Field'].'`)';
  35.         $fieldnames[]=$row['Field'];
  36.     }
  37.     mysql_free_result($fieldsres);
  38.     $bytesizequery "SUM(".implode('+',$fields).") AS `bytesize`";
  39.     $query "SELECT COUNT(*) AS `rowcount`, $bytesizequery FROM `$table`";
  40.     $res mysql_query($query);
  41.     $stats['rows'mysql_result($res,0,'rowcount');
  42.     $stats['bytesize'mysql_result($res,0,'bytesize');
  43.     mysql_free_result($res);
  44.     if(in_array("actual_device_root",$fieldnames)){
  45.         $res mysql_query("SELECT COUNT(*) AS `devcountFROM `$tableWHERE actual_device_root=1");
  46.         $stats['actual_devices'mysql_result($res,0,'devcount');
  47.         mysql_free_result($res);
  48.     }
  49.     return($stats);
  50. }
  51. function filesize_format($bytes){
  52.   $bytes=(float)$bytes;
  53.   if ($bytes<1024){
  54.   $numero=number_format($bytes0'.'',')." Bytes";
  55.   return $numero;
  56.   }
  57.   if ($bytes<1048576){
  58.      $numero=number_format($bytes/10242'.'',')." KB";
  59.   return $numero;
  60.   }
  61.   if ($bytes>=1048576){
  62.      $numero=number_format($bytes/10485762'.'',')." MB";
  63.   return $numero;
  64.   }
  65. }
  66. $devicestats tableStats(DB_DEVICE_TABLE);
  67. $patchstats tableStats(DB_PATCH_TABLE);
  68. $hybridstats tableStats(DB_HYBRID_TABLE);
  69. $cachestats tableStats(DB_CACHE_TABLE);
  70.  
  71.     $lastloglines "Empty";
  72. }else{
  73.     $logarr file(WURFL_LOG_FILE);
  74.     $loglines 30;
  75.     $end count($logarr)-1;
  76.     $lastloglines '';
  77.     for($i=$end;$i>=($end-$loglines);$i--){
  78.         $lastloglines .= htmlspecialchars($logarr[$i])."<br />";
  79.     }
  80. }
  81.  
  82. ?>
  83. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  84. <html xmlns="http://www.w3.org/1999/xhtml">
  85. <head>
  86. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  87. <title>Tera-WURFL Administration</title>
  88. <link href="style.css" rel="stylesheet" type="text/css" />
  89. </head>
  90.  
  91. <body>
  92. <table width="800">
  93.     <tr><td>
  94. <div align="center" class="titlediv">
  95.     <p>        Tera-WURFL Administration<br />
  96.         <span class="version">Version <?php echo "$branch $version"?></span></p>
  97. </div>
  98. </td></tr><tr><td>
  99.         <h3><br />
  100.             <a href="index.php">&lt;&lt; Back    to main page </a></h3>
  101.         <table width="800" border="0" cellspacing="0" cellpadding="0">
  102.         <tr>
  103.             <th scope="col">Database Table </th>
  104.             <th scope="col">Statistics</th>
  105.         </tr>
  106.         <tr>
  107.             <td width="145" class="darkrow">DB_DEVICE_TABLE<br />
  108.                     <span class="setting"><?=DB_DEVICE_TABLE?></span></td>
  109.             <td width="655" class="darkrow">Rows: <span class="setting"><?=$devicestats['rows']?></span><br />
  110.                 Actual Devices: <span class="setting"><?=$devicestats['actual_devices']?></span> <br />
  111.                 Table Size: <span class="setting"><?=filesize_format($devicestats['bytesize'])?></span><br />
  112.                 Purpose:<br />
  113.                 <span class="setting">The device table holds the data from the WURFL file, whether it be local, remote or remote CVS, the whenever a new WURFL is loaded, it is loaded into this table first. The data in this table is never modified, and if patching is disabled, this table is queried for the device in question. </span></td>
  114.         </tr>
  115.         <tr>
  116.             <td class="lightrow">DB_PATCH_TABLE        <br />
  117.                 <span class="setting"><?=DB_PATCH_TABLE?></span></td>
  118.             <td class="lightrow">Rows: <span class="setting"><?=$patchstats['rows']?></span><br />
  119.             Actual Devices: <span class="setting"><?=$patchstats['actual_devices']?></span>
  120.                 <br />
  121.                 Table Size: <span class="setting"><?=filesize_format($patchstats['bytesize'])?></span><br />
  122.                 Purpose:<br />
  123.                 <span class="setting">The patch table holds the data from the patch file, much like the device table, this data is not modified unless a new patch is loaded. When patching is enabled, this data is merged with the device table to create the hybrid table. </span></td>
  124.         </tr>
  125.         <tr>
  126.             <td class="darkrow">DB_HYBRID_TABLE        <span class="setting"><br />
  127.                 <?=DB_HYBRID_TABLE?></span></td>
  128.             <td class="darkrow">Rows: <span class="setting"><?=$hybridstats['rows']?></span><br />
  129.                 Actual Devices: <span class="setting"><?=$hybridstats['actual_devices']?></span> <br />
  130.                 Table Size: <span class="setting"><?=filesize_format($hybridstats['bytesize'])?></span><br />
  131.                 Purpose:<br />
  132.                 <span class="setting">The hybrid table is a combination of the device table and the patch table. <strong>People ask about this all the time so pay attention :) </strong>When you apply a patch to the main WURFL database, Tera-WURFL has to resolve conflicts between the main WURFL (the device table) and the patch table. Let's say you know that a Motorola RAZR has MP3 capability but the WURFL says it doesn't. You would figure out what WURFL DEVICE_ID the RAZR has, and you would add an entry in your patch file with that capability set correctly. Now, when you apply the patch, the script realizes that the RAZR exists in both the device table and the patch table - so it takes all the capabilities from the device table and puts them in the hybrid table, then it takes all your changes in the patch table and overwrites the existing ones in the hybrid table, effectively merging the conflicting items. Whenever your change the device or patch data you force Tera-WURFL to rebuild the hybrid table and you are presented with some stats about how many devices from your patch file are <strong>added</strong> and how many are <strong>merged</strong>. If you have patching enabled, this table is queried for the device in question. </span></td>
  133.         </tr>
  134.         <tr>
  135.             <td class="lightrow">DB_CACHE_TABLE        <br />
  136.                 <span class="setting"><?=DB_CACHE_TABLE?></span></td>
  137.             <td class="lightrow">Rows: <span class="setting"><?=$cachestats['rows']?></span><br />
  138.                 Table Size: <span class="setting"><?=filesize_format($cachestats['bytesize'])?></span><br />
  139.                 Purpose:<br />
  140.                 <span class="setting">The cache table stores unique user agents and the complete capabilities and device root that were determined the last time it was processed. <strong>Any time the patch or devices table is updated, the cache table is cleared</strong> since the underlying data may have been modified - leaving the cache tainted. </span></td>
  141.         </tr>
  142.     </table>
  143.     <p><br/>
  144.             <br/>
  145.     </p>
  146.     <table width="800" border="0" cellpadding="0" cellspacing="0">
  147.         <tr>
  148.             <th scope="col">Tera-WURFL Settings</th>
  149.         </tr>
  150.         <tr>
  151.             <td class="lightrow"><p>-- Database options --<br/>
  152.                 DB_HOST <span class="setting">
  153.     <?=DB_HOST?>
  154.     </span>,    database server hostname or IP<br />
  155.                 DB_USER <span class="setting">
  156.     <?=DB_USER?>
  157.     </span>,    database username (needs SELECT,INSERT,DELETE,DROP,CREATE)<br />
  158.                 DB_PASS <span class="setting">********</span>, database password<br />
  159.                 DB_SCHEMA <span class="setting">
  160.     <?=DB_SCHEMA?>
  161.     </span>, database schema (database name)<br />
  162.                 DB_TYPE <span class="setting">
  163.     <?=DB_TYPE?>
  164.     </span>, database table type (MyISAM, InnoDB, HEAP, etc...);<br />
  165.                 DB_DEVICE_TABLE <span class="setting">
  166.     <?=DB_DEVICE_TABLE?>
  167.     </span>, database table name for the WURFL<br />
  168.                 DB_PATCH_TABLE <span class="setting">
  169.     <?=DB_PATCH_TABLE?>
  170.     </span>, database table name for the patch<br />
  171.                 DB_HYBRID_TABLE <span class="setting"><?=DB_HYBRID_TABLE?></span>, database table name for the Hybrid of the WURFL and the patch<br />
  172.     DB_CACHE_TABLE <span class="setting"><?=DB_CACHE_TABLE?></span>, database table name for the cache <br />
  173.                     DB_MULTI_INSERT <span class="setting">
  174.                         <?=showBool(DB_MULTI_INSERT)?>
  175.                             </span>, use multiple inserts to speed DB updating<br />
  176.                     DB_MAX_INSERTS <span class="setting">
  177.                         <?=DB_MAX_INSERTS?>
  178.                             </span>, number of inserts per query<br />
  179.                     DB_EMPTY_METHOD <span class="setting">
  180.                         <?=DB_EMPTY_METHOD?>
  181.                             </span>, either DROP_CREATE or EMPTY; method for emptying tables.<br />
  182.                     DB_TEMP_EXT <span class="setting">
  183.                         <?=DB_TEMP_EXT?>
  184.                             </span>, extension that will be used for temporary tables like &quot;mytablename_TEMP&quot;<br />
  185.                             <br />
  186.                     -- General options --<br />
  187.                     WURFL_DL_URL <span class="setting">
  188.                         <?=WURFL_DL_URL?>
  189.                             </span>, full URL to the current WURFL<br />
  190.                     WURFL_CVS_URL <span class="setting">
  191.                         <?=WURFL_CVS_URL?>
  192.                             </span>, full URL to development (CVS) WURFL<br />
  193.                     WURFL_CONFIG <span class="setting">
  194.                         <?=showBool(WURFL_CONFIG)?>
  195.                             </span>,lets other file know the config is loaded<br />
  196.                     DATADIR <span class="setting">
  197.                         <?=DATADIR?>
  198.                             </span>,    where all data is stored (wurfl.xml, temp files, logs)<br />
  199.                     IMAGE_CHECKING <span class="setting">
  200.                         <?=showBool(IMAGE_CHECKING)?>
  201.                             </span>,checks the IMAGE_DIR for an image that matches the device<br />
  202.                     IMAGE_DIR <span class="setting">
  203.                         <?=IMAGE_DIR?>
  204.                             </span>, relative path to the device images with trailing slash<br />
  205.                             WURFL_CACHE_ENABLE <span class="setting"><?=showBool(WURFL_CACHE_ENABLE)?></span>, enables or disables the cache <br />
  206.                     WURFL_PATCH_ENABLE <span class="setting">
  207.                         <?=showBool(WURFL_PATCH_ENABLE)?>
  208.                         </span>, enables or disables the patch<br />
  209.                     WURFL_PATCH_FILE <span class="setting">
  210.                         <?=WURFL_PATCH_FILE?>
  211.                         </span>, optional patch file for WURFL<br />
  212.                     WURFL_PARSER_FILE <span class="setting">
  213.                         <?=WURFL_PARSER_FILE?>
  214.                         </span>, path and filename of wurfl_parser.php<br />
  215.                     WURFL_CLASS_FILE <span class="setting">
  216.                         <?=WURFL_CLASS_FILE?>
  217.                         </span>, path and filename of wurfl_class.php<br />
  218.                     WURFL_FILE <span class="setting">
  219.                         <?=WURFL_FILE?>
  220.                         </span>, path and filename of wurfl.xml<br />
  221.                     WURFL_LOG_FILE <span class="setting">
  222.                         <?=WURFL_LOG_FILE?>
  223.                         </span>, defines full path and filename for logging<br />
  224.                     LOG_LEVEL <span class="setting">
  225.                         <?=showLogLevel(LOG_LEVEL)?>
  226.                             </span>, desired logging level. Use the same constants as for PHP logging</p>
  227.                 </td>
  228.         </tr>
  229.     </table>
  230.     <p>&nbsp;</p>
  231.     <table width="800" border="0" cellpadding="0" cellspacing="0">
  232.         <tr>
  233.             <th scope="col">Log File (last 30 lines) </th>
  234.         </tr>
  235.         <tr>
  236.             <td class="lightrow"><div class="logfile"><?=$lastloglines?></div>
  237.                 <br/></td>
  238.         </tr>
  239.     </table>    <p>&nbsp; </p></td>
  240. </tr></table>
  241. </body>
  242. </html>

Documentation generated on Fri, 27 Apr 2007 12:10:15 -0400 by phpDocumentor 1.3.1