Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
memcached.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Session
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * Memcached session storage handler for PHP
14  *
15  * @package Joomla.Platform
16  * @subpackage Session
17  * @since 11.1
18  */
20 {
21  /**
22  * Constructor
23  *
24  * @param array $options Optional parameters.
25  *
26  * @since 11.1
27  * @throws RuntimeException
28  */
29  public function __construct($options = array())
30  {
31  if (!self::isSupported())
32  {
33  throw new RuntimeException('Memcached Extension is not available', 404);
34  }
35 
36  parent::__construct($options);
37 
38  $config = JFactory::getConfig();
39 
40  // This will be an array of loveliness
41  // @todo: multiple servers
42  $this->_servers = array(
43  array(
44  'host' => $config->get('memcache_server_host', 'localhost'),
45  'port' => $config->get('memcache_server_port', 11211)
46  )
47  );
48  }
49 
50  /**
51  * Register the functions of this class with PHP's session handler
52  *
53  * @return void
54  *
55  * @since 12.2
56  */
57  public function register()
58  {
59  ini_set('session.save_path', $this->_servers['host'] . ':' . $this->_servers['port']);
60  ini_set('session.save_handler', 'memcached');
61  }
62 
63  /**
64  * Test to see if the SessionHandler is available.
65  *
66  * @return boolean True on success, false otherwise.
67  *
68  * @since 12.1
69  */
70  static public function isSupported()
71  {
72  return (extension_loaded('memcached') && class_exists('Memcached'));
73  }
74 }