home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / System / SharedMemory.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  3.3 KB  |  116 lines

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
  4. /**
  5. *
  6. * common OO-style shared memory API
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * LICENSE: This source file is subject to version 3.0 of the PHP license
  11. * that is available through the world-wide-web at the following URI:
  12. * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  13. * the PHP License and are unable to obtain it through the web, please
  14. * send a note to license@php.net so we can mail you a copy immediately.
  15. *
  16. * @category   System
  17. * @package    System_Sharedmemory
  18. * @author     Evgeny Stepanischev <bolk@lixil.ru>
  19. * @copyright  2005 Evgeny Stepanischev
  20. * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  21. * @version    CVS: $Id:$
  22. * @link       http://pear.php.net/package/System_SharedMemory
  23. */
  24.  
  25. /**
  26. *
  27. * Backend independent OO-interface
  28. *
  29. * @category   System
  30. * @package    System_Sharedmemory
  31. * @package    System_Sharedmemory
  32. * @author     Evgeny Stepanischev <bolk@lixil.ru>
  33. * @copyright  2005 Evgeny Stepanischev
  34. * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  35. * @version    CVS: $Id:$
  36. * @link       http://pear.php.net/package/System_SharedMemory
  37. */
  38.  
  39. // {{{ class System_SharedMemory
  40.  
  41. class System_SharedMemory
  42. {
  43.     // {{{ &factory()
  44.  
  45.     /**
  46.      * Create a new shared mem object
  47.      *
  48.      * @param string $type  the shared mem type (or false on autodetect)
  49.      * @param array  $options  an associative array of option names and values
  50.      *
  51.      * @return object  a new System_Shared object
  52.      *
  53.      */
  54.     
  55.     function &factory($type = false, $options = array())
  56.     {
  57.         if ($type === false) {
  58.             $type = System_SharedMemory::getAvailableTypes(true);
  59.         } else {
  60.             $type = ucfirst(strtolower($type));
  61.         }
  62.  
  63.         require_once 'System/SharedMemory/'.$type . '.php';
  64.         $class = 'System_SharedMemory_' . $type;
  65.  
  66.         $ref = &new $class($options);
  67.         return $ref;
  68.     }
  69.  
  70.     // }}}
  71.     // {{{ getAvailableTypes()
  72.  
  73.     /**
  74.      * Get available types or first one
  75.      *
  76.      * @param bool $only_first false if need all types and true if only first one
  77.      *
  78.      * @return mixed list of available types (array) or first one (string)
  79.      *
  80.      */
  81.  
  82.      function getAvailableTypes($only_first = false)
  83.      {
  84.         $detect = array
  85.         (
  86.             'eaccelerator' => 'Eaccelerator',   // Eaccelerator (Turck MMcache fork)
  87.             'mmcache'      => 'Mmcache',        // Turck MMCache
  88.             'Memcache'     => 'Memcache',       // Memched
  89.             'shmop_open'   => 'Shmop',          // Shmop
  90.             'apc_fetch'    => 'Apc',            // APC
  91.             'apache_note'  => 'Apachenote',     // Apache note
  92.             'shm_get_var'  => 'Systemv',        // System V
  93.             'sqlite_open'  => 'Sqlite',         // SQLite
  94.             'file'         => 'File',           // Plain text
  95.             'fsockopen'    => 'Sharedance',     // Sharedance
  96.         );
  97.  
  98.         $types = array();
  99.  
  100.         foreach ($detect as $func=>$val) {
  101.             if (function_exists($func) || class_exists($func)) {
  102.                 if ($only_first) {
  103.                     return $val;
  104.                 }
  105.  
  106.                 $types[] = $val;
  107.             }
  108.         }
  109.  
  110.         return $types;
  111.      }
  112.  
  113.     // }}}
  114. }
  115. // }}}
  116. ?>