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

Source for file APC.php

Documentation is available at APC.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP version 4.2                                                      |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1997-2003 The PHP Group                                |
  6. // +----------------------------------------------------------------------+
  7. // | This source file is subject to version 2.0 of the PHP license,       |
  8. // | that is bundled with this package in the file LICENSE, and is        |
  9. // | available at through the world-wide-web at                           |
  10. // | http://www.php.net/license/2_02.txt.                                 |
  11. // | If you did not receive a copy of the PHP license and are unable to   |
  12. // | obtain it through the world-wide-web, please send a note to          |
  13. // | license@php.net so we can mail you a copy immediately.               |
  14. // +----------------------------------------------------------------------+
  15. // | Authors: Lucas Nealan <lucas@facebook.com>                           |
  16. // +----------------------------------------------------------------------+
  17.  
  18. // $Id: APC.php,v 1.2 2008/10/12 00:31:46 jrust Exp $
  19.  
  20. require_once 'Net/UserAgent/Detect.php';
  21.  
  22. {
  23.     var $key = '';
  24.  
  25.     function Net_UserAgent_Detect_APC($in_userAgent = null$in_detect = null$ua_cache_window = 600)
  26.     {
  27.         $data '';
  28.         $restored = false;
  29.         $ua_cache_timeout = apc_fetch('useragent:cache_timeout');               // don't cache after time period
  30.  
  31.         if ($ua_cache_window > 0{
  32.             if (!$ua_cache_timeout{
  33.                 // check apc uptime and disable after x mins
  34.                 $apc_data = apc_cache_info('file'true);
  35.  
  36.                 if (isset($apc_data['start_time'])) {
  37.                     $uptime $apc_data['start_time'];
  38.  
  39.                     if (time($uptime $ua_cache_window// timeout and disable after 10 minutes of uptime
  40.                         apc_store('useragent:cache_timeout'true);
  41.                         $ua_cache_timeout = true; // don't cache this one either
  42.                     }
  43.                 }
  44.             }
  45.  
  46.             if (!$this->key{
  47.                 $key_flags '';
  48.                 if ($in_detect !== null{
  49.                     $key_flags implode('-'$in_detect);
  50.                 }
  51.                 $this->key = 'useragent:'.md5($in_userAgent.$key_flags);
  52.             }
  53.  
  54.             if ($data = apc_fetch($this->key)) {
  55.                 $success = null;
  56.                 $data unserialize($data);
  57.                 if ($data{
  58.                     $restored $this->cache_restore($data);
  59.                 }
  60.             }
  61.         }
  62.  
  63.         if (!$data{
  64.             $this->detect($in_userAgent$in_detect);
  65.  
  66.             if ($ua_cache_window > 0 && !$ua_cache_timeout{
  67.                 $this->cache_save();
  68.             }
  69.         }
  70.     }
  71.  
  72.     function &singleton($in_userAgent = null$in_detect = null
  73.     {
  74.         static $instance;
  75.  
  76.         if (!isset($instance)) {
  77.             $instance = new Net_UserAgent_Detect_APC($in_userAgent$in_detect);
  78.         }
  79.  
  80.         return $instance;
  81.     }
  82.  
  83.     function cache_restore($cache
  84.     {
  85.         if (is_array($cache)) {
  86.             foreach($cache as $prop => $value{
  87.                 $ptr Net_UserAgent_Detect::_getStaticProperty($prop);
  88.                 $ptr $value;
  89.             }
  90.             return true;
  91.         }
  92.         return false;
  93.     }
  94.  
  95.     function cache_save(
  96.     {
  97.         if ($this->key{
  98.             $data = array('browser'           => Net_UserAgent_Detect::_getStaticProperty('browser'),
  99.                           'features'          => Net_UserAgent_Detect::_getStaticProperty('features'),
  100.                           'leadingIdentifier' => Net_UserAgent_Detect::_getStaticProperty('leadingIdentifier'),
  101.                           'majorVersion'      => Net_UserAgent_Detect::_getStaticProperty('majorVersion'),
  102.                           'options'           => Net_UserAgent_Detect::_getStaticProperty('options'),
  103.                           'os'                => Net_UserAgent_Detect::_getStaticProperty('os'),
  104.                           'quirks'            => Net_UserAgent_Detect::_getStaticProperty('quirks'),
  105.                           'subVersion'        => Net_UserAgent_Detect::_getStaticProperty('subVersion'),
  106.                           'userAgent'         => Net_UserAgent_Detect::_getStaticProperty('userAgent'),
  107.                           'version'           => Net_UserAgent_Detect::_getStaticProperty('version'),
  108.                          );
  109.             apc_store($this->keyserialize($data));
  110.         }
  111.     }
  112. }
  113. ?>

Documentation generated on Mon, 11 Mar 2019 15:25:53 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.