[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Part of the Joomla Framework Session Package 4 * 5 * @copyright Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE 7 */ 8 9 namespace Joomla\Session\Handler; 10 11 use Joomla\Session\HandlerInterface; 12 13 /** 14 * APCu session storage handler 15 * 16 * @since 2.0.0 17 */ 18 class ApcuHandler implements HandlerInterface 19 { 20 /** 21 * Session ID prefix to avoid naming conflicts 22 * 23 * @var string 24 * @since 2.0.0 25 */ 26 private $prefix; 27 28 /** 29 * Constructor 30 * 31 * @param array $options Associative array of options to configure the handler 32 * 33 * @since 2.0.0 34 */ 35 public function __construct(array $options = []) 36 { 37 // Namespace our session IDs to avoid potential conflicts 38 $this->prefix = $options['prefix'] ?? 'jfw'; 39 } 40 41 /** 42 * Close the session 43 * 44 * @return boolean True on success, false otherwise 45 * 46 * @since 2.0.0 47 */ 48 #[\ReturnTypeWillChange] 49 public function close() 50 { 51 return true; 52 } 53 54 /** 55 * Destroy a session 56 * 57 * @param integer $session_id The session ID being destroyed 58 * 59 * @return boolean True on success, false otherwise 60 * 61 * @since 2.0.0 62 */ 63 public function destroy($session_id): bool 64 { 65 // The apcu_delete function returns false if the id does not exist 66 return apcu_delete($this->prefix . $session_id) || !apcu_exists($this->prefix . $session_id); 67 } 68 69 /** 70 * Cleanup old sessions 71 * 72 * @param integer $maxlifetime Sessions that have not updated for the last maxlifetime seconds will be removed 73 * 74 * @return boolean True on success, false otherwise 75 * 76 * @since 2.0.0 77 */ 78 #[\ReturnTypeWillChange] 79 public function gc($maxlifetime) 80 { 81 return true; 82 } 83 84 /** 85 * Test to see if the HandlerInterface is available 86 * 87 * @return boolean True on success, false otherwise 88 * 89 * @since 2.0.0 90 */ 91 public static function isSupported(): bool 92 { 93 $supported = \extension_loaded('apcu') && ini_get('apc.enabled'); 94 95 // If on the CLI interface, the `apc.enable_cli` option must also be enabled 96 if ($supported && PHP_SAPI === 'cli') 97 { 98 $supported = ini_get('apc.enable_cli'); 99 } 100 101 return (bool) $supported; 102 } 103 104 /** 105 * Initialize session 106 * 107 * @param string $save_path The path where to store/retrieve the session 108 * @param string $session_id The session id 109 * 110 * @return boolean True on success, false otherwise 111 * 112 * @since 2.0.0 113 */ 114 #[\ReturnTypeWillChange] 115 public function open($save_path, $session_id) 116 { 117 return true; 118 } 119 120 /** 121 * Read session data 122 * 123 * @param string $session_id The session id to read data for 124 * 125 * @return string The session data 126 * 127 * @since 2.0.0 128 */ 129 #[\ReturnTypeWillChange] 130 public function read($session_id) 131 { 132 return (string) apcu_fetch($this->prefix . $session_id); 133 } 134 135 /** 136 * Write session data 137 * 138 * @param string $session_id The session id 139 * @param string $session_data The encoded session data 140 * 141 * @return boolean True on success, false otherwise 142 * 143 * @since 2.0.0 144 */ 145 #[\ReturnTypeWillChange] 146 public function write($session_id, $session_data) 147 { 148 return apcu_store($this->prefix . $session_id, $session_data, ini_get('session.gc_maxlifetime')); 149 } 150 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |