1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Session
5 *
6 * @copyright Copyright (C) 2005 - 2017 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 * @since 11.1
16 * @deprecated 4.0 The CMS' Session classes will be replaced with the `joomla/session` package
17 */
18 class JSessionStorageMemcached extends JSessionStorage
19 {
20 /**
21 * @var array Container for memcache server conf arrays
22 */
23 private $_servers = array();
24
25 /**
26 * Constructor
27 *
28 * @param array $options Optional parameters.
29 *
30 * @since 11.1
31 * @throws RuntimeException
32 */
33 public function __construct($options = array())
34 {
35 if (!self::isSupported())
36 {
37 throw new RuntimeException('Memcached Extension is not available', 404);
38 }
39
40 $config = JFactory::getConfig();
41
42 // This will be an array of loveliness
43 // @todo: multiple servers
44 $this->_servers = array(
45 array(
46 'host' => $config->get('session_memcached_server_host', 'localhost'),
47 'port' => $config->get('session_memcached_server_port', 11211),
48 ),
49 );
50
51 parent::__construct($options);
52 }
53
54 /**
55 * Register the functions of this class with PHP's session handler
56 *
57 * @return void
58 *
59 * @since 12.2
60 */
61 public function register()
62 {
63 if (!empty($this->_servers) && isset($this->_servers[0]))
64 {
65 $serverConf = current($this->_servers);
66 ini_set('session.save_path', "{$serverConf['host']}:{$serverConf['port']}");
67 ini_set('session.save_handler', 'memcached');
68 }
69 }
70
71 /**
72 * Test to see if the SessionHandler is available.
73 *
74 * @return boolean True on success, false otherwise.
75 *
76 * @since 12.1
77 */
78 public static function isSupported()
79 {
80 return extension_loaded('memcached') && class_exists('Memcached');
81 }
82 }
83