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 * APC session storage handler for PHP
14 *
15 * @link https://secure.php.net/manual/en/function.session-set-save-handler.php
16 * @since 11.1
17 * @deprecated 4.0 The CMS' Session classes will be replaced with the `joomla/session` package
18 */
19 class JSessionStorageApc extends JSessionStorage
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('APC Extension is not available', 404);
34 }
35
36 parent::__construct($options);
37 }
38
39 /**
40 * Read the data for a particular session identifier from the
41 * SessionHandler backend.
42 *
43 * @param string $id The session identifier.
44 *
45 * @return string The session data.
46 *
47 * @since 11.1
48 */
49 public function read($id)
50 {
51 $sess_id = 'sess_' . $id;
52
53 return (string) apc_fetch($sess_id);
54 }
55
56 /**
57 * Write session data to the SessionHandler backend.
58 *
59 * @param string $id The session identifier.
60 * @param string $session_data The session data.
61 *
62 * @return boolean True on success, false otherwise.
63 *
64 * @since 11.1
65 */
66 public function write($id, $session_data)
67 {
68 $sess_id = 'sess_' . $id;
69
70 return apc_store($sess_id, $session_data, ini_get('session.gc_maxlifetime'));
71 }
72
73 /**
74 * Destroy the data for a particular session identifier in the SessionHandler backend.
75 *
76 * @param string $id The session identifier.
77 *
78 * @return boolean True on success, false otherwise.
79 *
80 * @since 11.1
81 */
82 public function destroy($id)
83 {
84 $sess_id = 'sess_' . $id;
85
86 return apc_delete($sess_id);
87 }
88
89 /**
90 * Test to see if the SessionHandler is available.
91 *
92 * @return boolean True on success, false otherwise.
93 *
94 * @since 12.1
95 */
96 public static function isSupported()
97 {
98 return extension_loaded('apc');
99 }
100 }
101