3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Session Wrapper Object * * Provides abstract support for session handling * * @author Harold Asbridge * @package Sphere * @subpackage Core * @version 3.0 * */ class Session { /** * The current user's session id * * @var string */ public $id; /** * Whether or not the session is open * * @var bool */ public $open = false; /** * Flash data identifier * * @var string */ public $flashdata_key = 'flash'; /** * Flash data * * @var array */ public $userdata = array(); /** * Constructor method - init session * */ public function __construct() { $sesDir = '/var/lib/php/session'; // Set session save path to app-relative dir, if it exists //if (file_exists(BASE_DIR.'/sessions')) if (file_exists($sesDir)) { //if (is_writable(BASE_DIR.'/sessions')) if (is_writable($sesDir)) { //session_save_path(BASE_DIR.'/sessions'); session_save_path($sesDir); } } // Set session cookie to the base href, useful for multiple sites on the same domain if (BASE_HREF != "") { session_set_cookie_params(0, BASE_HREF); } else { session_set_cookie_params(0); } // Begin session session_start(); $this->id = session_id(); $this->open = true; // Initalize Flash Data $this->userdata = ($this->Get('flash_userdata')) ? $this->Get('flash_userdata') : array(); // Delete 'old' flashdata (from last request) $this->_flashdata_sweep(); // Mark all new flashdata as old (data will be deleted before next request) $this->_flashdata_mark(); } /** * Get session value * * @param string $key * @return mixed|null */ public function Get($key) { if (isset($_SESSION[$key])) { return $_SESSION[$key]; } return null; } /** * Set session value * * @param string $key * @param mixed $value * @return bool */ public function Set($key, $value) { $_SESSION[$key] = $value; return true; } /** * Unset a session value * * @param string $key */ public function Clear($key) { if (isset($_SESSION[$key])) { unset($_SESSION[$key]); return true; } return false; } /** * Empty all session vars * * @return bool */ public function Destroy() { $_SESSION = array(); return true; } /** * Close session * * @return bool */ public function Close() { if ($this->open) { session_write_close(); $this->open = false; return true; } return false; } /** * Sets flash data * * @access plublic * @param mixed * @param mixed * @return void */ public function set_flashdata($newdata = array(), $newval = '') { if (is_string($newdata)) { $newdata = array($newdata => $newval); } if (count($newdata) > 0) { foreach ($newdata as $key => $val) { $flashdata_key = $this->flashdata_key.':new:'.$key; $this->set_userdata($flashdata_key, $val); } } } /** * Sets old flash data to new so it will last another page load * * @access plublic * @param string * @return void */ public function keep_flashdata($key) { // 'old' flashdata gets removed. Here we mark all // flashdata as 'new' to preserve it from _flashdata_sweep() // Note the function will return FALSE if the $key // provided cannot be found $old_flashdata_key = $this->flashdata_key.':old:'.$key; $value = $this->userdata($old_flashdata_key); $new_flashdata_key = $this->flashdata_key.':new:'.$key; $this->set_userdata($new_flashdata_key, $value); } /** * Retrieves flash data * * @access plublic * @param string * @return mixed */ public function flashdata($key) { $flashdata_key = $this->flashdata_key.':old:'.$key; return $this->userdata($flashdata_key); } /** * Identifies flashdata as 'old' for removal * when _flashdata_sweep() runs. * * @access private * @return void */ private function _flashdata_mark() { $userdata = $this->all_userdata(); foreach ($userdata as $name => $value) { $parts = explode(':new:', $name); if (is_array($parts) && count($parts) === 2) { $new_name = $this->flashdata_key.':old:'.$parts[1]; $this->set_userdata($new_name, $value); $this->unset_userdata($name); } } } /** * Removes all flashdata marked as 'old' * * @access private * @return void */ private function _flashdata_sweep() { $userdata = $this->all_userdata(); foreach ($userdata as $key => $value) { if (strpos($key, ':old:')) { $this->unset_userdata($key); } } } /** * Fetch a specific item from the session array * * @access public * @param string * @return string */ public function userdata($item) { return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; } /** * Add or change data in the "userdata" array * * @access public * @param mixed * @param string * @return void */ public function set_userdata($newdata = array(), $newval = '') { if (is_string($newdata)) { $newdata = array($newdata => $newval); } if (count($newdata) > 0) { foreach ($newdata as $key => $val) { $this->userdata[$key] = $val; } } $this->Set('flash_userdata', $this->userdata); } /** * Delete a session variable from the "userdata" array * * @access array * @return void */ public function unset_userdata($newdata = array()) { if (is_string($newdata)) { $newdata = array($newdata => ''); } if (count($newdata) > 0) { foreach ($newdata as $key => $val) { unset($this->userdata[$key]); } } $this->Set('flash_userdata', $this->userdata); } /** * Fetch a specific item from the session array * * @access public * @return array */ public function all_userdata() { return ( ! isset($this->userdata)) ? FALSE : $this->userdata; } /** * Destructor method - save all session data before exiting * */ public function __destruct() { $this->Close(); } } ?>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0110.01118.07
8.3.50.0130.00621.95
8.3.40.0090.00618.98
8.3.30.0160.00619.13
8.3.20.0120.00622.13
8.3.10.0090.00923.54
8.3.00.0060.00619.18
8.2.180.0070.00718.16
8.2.170.0140.01018.96
8.2.160.0140.00722.96
8.2.150.0070.00424.18
8.2.140.0030.00624.66
8.2.130.0150.00326.16
8.2.120.0040.00420.97
8.2.110.0090.00020.99
8.2.100.0060.00617.91
8.2.90.0070.00319.38
8.2.80.0080.00019.34
8.2.70.0050.00517.50
8.2.60.0070.00317.68
8.2.50.0100.00018.07
8.2.40.0050.00318.16
8.2.30.0040.00418.11
8.2.20.0000.00817.74
8.2.10.0000.00818.02
8.2.00.0030.00517.95
8.1.280.0080.00825.92
8.1.270.0030.00620.46
8.1.260.0050.00526.35
8.1.250.0090.00028.09
8.1.240.0030.00622.42
8.1.230.0050.00521.02
8.1.220.0000.00817.74
8.1.210.0040.00418.90
8.1.200.0060.00317.23
8.1.190.0030.00617.53
8.1.180.0000.00818.10
8.1.170.0050.00318.74
8.1.160.0030.00518.76
8.1.150.0070.00018.79
8.1.140.0040.00417.32
8.1.130.0040.00417.88
8.1.120.0000.00717.35
8.1.110.0060.00317.41
8.1.100.0050.00217.25
8.1.90.0030.00617.30
8.1.80.0070.00317.44
8.1.70.0000.00817.38
8.1.60.0000.00817.52
8.1.50.0070.00717.50
8.1.40.0040.00417.44
8.1.30.0030.00517.54
8.1.20.0000.01117.56
8.1.10.0030.00517.45
8.1.00.0040.00417.39
8.0.300.0060.00319.98
8.0.290.0000.00816.75
8.0.280.0070.00018.45
8.0.270.0000.00817.17
8.0.260.0030.00317.21
8.0.250.0000.00716.92
8.0.240.0000.00716.77
8.0.230.0000.00816.95
8.0.220.0070.00016.75
8.0.210.0030.00316.74
8.0.200.0000.00716.82
8.0.190.0050.00516.88
8.0.180.0000.00716.78
8.0.170.0030.00516.78
8.0.160.0000.00816.86
8.0.150.0040.00416.78
8.0.140.0000.00816.73
8.0.130.0000.00613.29
8.0.120.0000.00816.79
8.0.110.0040.00416.86
8.0.100.0040.00416.79
8.0.90.0050.00516.89
8.0.80.0030.01316.83
8.0.70.0040.00416.82
8.0.60.0040.00416.84
8.0.50.0080.00016.82
8.0.30.0090.01316.93
8.0.20.0140.00517.40
8.0.10.0040.00416.77
8.0.00.0090.01016.63
7.4.330.0050.00015.03
7.4.320.0060.00016.49
7.4.300.0030.00316.56
7.4.290.0030.00316.45
7.4.280.0030.00616.46
7.4.270.0070.00016.39
7.4.260.0000.00716.59
7.4.250.0000.00716.35
7.4.240.0010.00616.45
7.4.230.0000.00816.58
7.4.220.0090.00916.62
7.4.210.0070.00916.53
7.4.200.0040.00416.64
7.4.160.0170.00016.49
7.4.150.0160.00317.40
7.4.140.0090.01317.86
7.4.130.0090.00916.43
7.4.120.0090.01216.55
7.4.110.0090.01216.46
7.4.100.0120.00616.33
7.4.90.0190.00316.50
7.4.80.0130.01019.39
7.4.70.0170.00016.38
7.4.60.0130.00416.54
7.4.50.0030.00616.39
7.4.40.0030.01316.30
7.4.30.0090.00916.48
7.4.00.0100.00514.73
7.3.330.0030.00313.11
7.3.320.0070.00713.31
7.3.310.0040.00416.23
7.3.300.0060.00016.24
7.3.290.0060.00316.11
7.3.280.0110.00716.25
7.3.270.0100.01317.40
7.3.260.0090.00916.50
7.3.250.0100.00816.25
7.3.240.0130.00616.52
7.3.230.0120.01116.39
7.3.210.0140.00716.18
7.3.200.0070.01619.39
7.3.190.0110.00816.58
7.3.180.0100.01016.34
7.3.170.0060.01616.47
7.3.160.0130.00616.19
7.3.120.0040.00914.78
7.3.110.0120.00414.95
7.3.100.0110.00314.68
7.3.90.0100.00314.98
7.3.80.0080.00614.59
7.3.70.0030.00614.73
7.3.60.0060.00914.73
7.3.50.0060.01014.43
7.3.40.0100.00314.91
7.3.30.0080.00314.86
7.3.20.0000.00816.57
7.3.10.0060.00916.52
7.3.00.0040.01116.29
7.2.330.0140.00316.68
7.2.320.0060.01116.61
7.2.310.0070.01016.38
7.2.300.0060.01016.45
7.2.290.0080.00816.69
7.2.250.0070.01315.04
7.2.240.0100.01015.10
7.2.230.0000.01515.01
7.2.220.0070.00714.87
7.2.210.0060.00614.71
7.2.200.0140.00014.89
7.2.190.0110.00314.96
7.2.180.0060.00914.84
7.2.170.0030.00914.91
7.2.160.0000.01114.54
7.2.150.0060.00916.59
7.2.140.0040.01516.66
7.2.130.0030.01316.75
7.2.120.0030.00616.55
7.2.110.0040.00816.65
7.2.100.0090.00616.56
7.2.90.0060.00616.94
7.2.80.0130.00316.77
7.2.70.0090.00616.60
7.2.60.0080.00616.67
7.2.50.0100.00616.81
7.2.40.0060.00916.44
7.2.30.0070.00716.55
7.2.20.0040.01216.78
7.2.10.0040.01116.76
7.2.00.0080.00618.04
7.1.330.0070.00715.73
7.1.320.0060.00915.68
7.1.310.0030.01015.71
7.1.300.0080.00315.41
7.1.290.0060.00915.33
7.1.280.0030.00715.41
7.1.270.0060.00915.35
7.1.260.0030.01015.63
7.1.250.0070.00715.54
7.1.240.0000.01515.73
7.1.230.0030.01315.66
7.1.220.0030.00715.66
7.1.210.0100.00715.50
7.1.200.0040.01115.65
7.1.190.0030.01215.46
7.1.180.0070.00715.65
7.1.170.0070.00715.75
7.1.160.0060.00615.69
7.1.150.0090.00915.59
7.1.140.0120.00315.56
7.1.130.0000.01815.61
7.1.120.0000.01715.58
7.1.110.0000.01315.66
7.1.100.0040.00816.79
7.1.90.0090.00615.78
7.1.80.0030.01315.63
7.1.70.0010.00916.13
7.1.60.0060.00817.50
7.1.50.0070.01116.30
7.1.40.0060.01015.28
7.1.30.0060.01215.80
7.1.20.0080.00815.74
7.1.10.0030.00915.61
7.1.00.0070.04019.00
7.0.330.0000.00815.06
7.0.320.0040.00415.22
7.0.310.0060.01015.24
7.0.300.0090.00615.39
7.0.290.0100.00315.22
7.0.280.0040.00414.88
7.0.270.0070.00415.19
7.0.260.0070.00715.21
7.0.250.0030.01215.18
7.0.240.0030.01215.26
7.0.230.0090.00615.14
7.0.220.0030.01015.20
7.0.210.0030.01015.14
7.0.200.0070.00515.96
7.0.190.0030.01015.28
7.0.180.0100.00315.30
7.0.170.0070.00315.41
7.0.160.0030.01315.41
7.0.150.0110.00415.06
7.0.140.0060.00314.91
7.0.130.0040.01115.28
7.0.120.0050.00515.26
7.0.110.0000.01315.29
7.0.100.0030.00915.18
7.0.90.0100.00315.25
7.0.80.0070.00715.10
7.0.70.0040.00415.42
7.0.60.0050.02317.73
7.0.50.0050.04516.59
7.0.40.0080.04216.85
7.0.30.0190.02616.56
7.0.20.0200.03916.73
7.0.10.0130.02216.76
7.0.00.0070.04716.76
5.6.400.0000.01114.01
5.6.390.0120.00314.12
5.6.380.0000.00914.12
5.6.370.0080.00414.38
5.6.360.0070.00714.17
5.6.350.0040.00814.02
5.6.340.0000.00914.17
5.6.330.0060.01214.03
5.6.320.0060.00614.52
5.6.310.0030.01314.44
5.6.300.0070.00714.34
5.6.290.0000.01214.33
5.6.280.0050.04017.55
5.6.270.0060.00314.24
5.6.260.0000.01514.28
5.6.250.0030.00614.18
5.6.240.0030.00714.26
5.6.230.0060.00314.15
5.6.220.0040.00714.26
5.6.210.0050.04517.39
5.6.200.0070.03416.10
5.6.190.0120.02717.40
5.6.180.0090.02317.36
5.6.170.0080.03517.25
5.6.160.0080.04117.38
5.6.150.0070.02616.39
5.6.140.0050.02316.13
5.6.130.0060.04616.13
5.6.120.0050.04217.57
5.6.110.0020.04917.65
5.6.100.0080.04217.81
5.6.90.0110.04217.63
5.6.80.0130.03817.22
5.6.70.2180.02617.29
5.6.60.0120.00613.97
5.6.50.0040.00814.02
5.6.40.0070.00714.27
5.6.30.0120.00314.24
5.6.20.0030.01014.40
5.6.10.0100.00313.99
5.6.00.0000.01014.00
5.5.380.0100.00714.21
5.5.370.0080.00814.09
5.5.360.0040.01114.28
5.5.350.0070.04817.07
5.5.340.0020.05016.05
5.5.330.0030.04817.34
5.5.320.0160.04117.23
5.5.310.0170.02017.28
5.5.300.0030.04516.31
5.5.290.0070.03316.11
5.5.280.0080.04517.58
5.5.270.0020.05117.47
5.5.260.0070.04617.38
5.5.250.0050.03617.35
5.5.240.0050.03917.14
5.5.230.0000.01513.89
5.5.220.0060.00913.85
5.5.210.0030.00913.66
5.5.200.0030.01014.03
5.5.190.0000.01914.13
5.5.180.0060.01213.87
5.5.170.0040.01114.00
5.5.160.0000.01513.87
5.5.150.0060.01213.60
5.5.140.0060.01213.93
5.5.130.0070.01013.96
5.5.120.0070.00313.58
5.5.110.0060.00914.07
5.5.100.0070.00713.79
5.5.90.0000.01313.81
5.5.80.0040.01114.11
5.5.70.0100.00613.83
5.5.60.0030.01013.96
5.5.50.0030.01314.06
5.5.40.0050.00513.58
5.5.30.0040.00814.00
5.5.20.0030.00713.91
5.5.10.0040.00814.13
5.5.00.0110.00013.82
5.4.450.0150.04215.50
5.4.440.0160.03415.39
5.4.430.0130.02715.45
5.4.420.0130.03215.49
5.4.410.0170.03015.51
5.4.400.0130.02215.23
5.4.390.0160.03015.37
5.4.380.0160.02515.30
5.4.370.0130.02215.35
5.4.360.0150.02615.33
5.4.350.0160.04315.23
5.4.340.0210.03015.32
5.4.330.0080.00011.51
5.4.320.0150.02615.33
5.4.310.0110.03015.30
5.4.300.0200.02515.29
5.4.290.0180.02515.41
5.4.280.0190.03515.30
5.4.270.0150.03115.25
5.4.260.0170.03415.33
5.4.250.0170.03515.34
5.4.240.0190.03515.37
5.4.230.0150.03515.30
5.4.220.0150.02515.41
5.4.210.0170.03715.37
5.4.200.0130.02315.19
5.4.190.0150.03615.18
5.4.180.0150.03415.24
5.4.170.0150.02415.36
5.4.160.0150.03815.37
5.4.150.0120.02515.36
5.4.140.0150.03514.04
5.4.130.0150.03813.98
5.4.120.0130.03613.99
5.4.110.0150.02714.06
5.4.100.0130.02313.96
5.4.90.0120.03014.06
5.4.80.0220.03514.04
5.4.70.0190.01913.90
5.4.60.0160.02013.94
5.4.50.0170.02914.04
5.4.40.0150.03314.05
5.4.30.0180.03713.99
5.4.20.0200.03514.04
5.4.10.0150.02514.04
5.4.00.0130.02013.75
5.3.290.0230.04314.80
5.3.280.0300.04014.63
5.3.270.0300.05714.75
5.3.260.0270.05014.58
5.3.250.0200.08014.65
5.3.240.0330.06314.64
5.3.230.0270.05714.63
5.3.220.0270.04714.84
5.3.210.0270.07714.63
5.3.200.0300.04014.53
5.3.190.0230.05314.71
5.3.180.0270.05014.70
5.3.170.0330.07014.64
5.3.160.0230.04314.62
5.3.150.0300.04314.64
5.3.140.0370.05314.53
5.3.130.0330.06014.52
5.3.120.0330.03314.58
5.3.110.0300.04314.52
5.3.100.0300.03714.03
5.3.90.0330.06714.16
5.3.80.0300.05313.98
5.3.70.0330.04714.14
5.3.60.0400.05714.06
5.3.50.0230.03713.91
5.3.40.0330.06314.05
5.3.30.0300.06314.08
5.3.20.0330.04313.66
5.3.10.0170.04713.61
5.3.00.0230.05313.91
5.2.170.0200.06012.02
5.2.160.0230.03012.02
5.2.150.0300.04312.02
5.2.140.0270.04312.02
5.2.130.0200.06312.02
5.2.120.0200.05712.02
5.2.110.0170.04312.02
5.2.100.0200.03712.02
5.2.90.0170.04312.02
5.2.80.0230.03312.02
5.2.70.0270.05012.02
5.2.60.0200.04012.02
5.2.50.0270.04012.02
5.2.40.0170.03312.02
5.2.30.0300.05312.02
5.2.20.0230.05012.02
5.2.10.0230.04012.02
5.2.00.0170.05012.02
5.1.60.0130.03712.02
5.1.50.0230.02712.02
5.1.40.0200.05312.02
5.1.30.0170.04712.02
5.1.20.0200.05312.02
5.1.10.0230.05312.02
5.1.00.0130.04012.02
5.0.50.0100.02712.02
5.0.40.0100.02712.02
5.0.30.0100.03312.02
5.0.20.0130.02712.02
5.0.10.0070.03312.02
5.0.00.0070.04312.02
4.4.90.0100.03312.02
4.4.80.0100.03312.02
4.4.70.0100.03712.02
4.4.60.0100.03712.02
4.4.50.0070.03012.02
4.4.40.0070.03312.02
4.4.30.0100.03312.02
4.4.20.0100.03312.02
4.4.10.0070.02312.02
4.4.00.0070.03712.02
4.3.110.0100.02012.02
4.3.100.0130.02012.02
4.3.90.0100.01312.02
4.3.80.0070.05712.02
4.3.70.0070.02712.02
4.3.60.0070.02012.02
4.3.50.0070.01312.02
4.3.40.0100.03012.02
4.3.30.0030.03312.02
4.3.20.0070.01312.02
4.3.10.0030.01712.02
4.3.00.0030.02012.02

preferences:
74.58 ms | 401 KiB | 5 Q