@@ -26,6 +26,11 @@ class Redis_Test extends TestSuite
26
26
*/
27
27
protected $ sessionPrefix = 'PHPREDIS_SESSION: ' ;
28
28
29
+ /**
30
+ * @var string
31
+ */
32
+ protected $ sessionSaveHandler = 'redis ' ;
33
+
29
34
public function setUp () {
30
35
$ this ->redis = $ this ->newInstance ();
31
36
$ info = $ this ->redis ->info ();
@@ -5217,7 +5222,7 @@ public function testSession_lockReleasedOnClose()
5217
5222
$ this ->assertFalse ($ this ->redis ->exists ($ this ->sessionPrefix . $ sessionId . '_LOCK ' ));
5218
5223
}
5219
5224
5220
- public function testSession_ttlMaxExecutionTime ()
5225
+ public function testSession_lock_ttlMaxExecutionTime ()
5221
5226
{
5222
5227
$ this ->setSessionHandler ();
5223
5228
$ sessionId = $ this ->generateSessionId ();
@@ -5233,7 +5238,7 @@ public function testSession_ttlMaxExecutionTime()
5233
5238
$ this ->assertTrue ($ sessionSuccessful );
5234
5239
}
5235
5240
5236
- public function testSession_ttlLockExpire ()
5241
+ public function testSession_lock_ttlLockExpire ()
5237
5242
{
5238
5243
$ this ->setSessionHandler ();
5239
5244
$ sessionId = $ this ->generateSessionId ();
@@ -5468,12 +5473,43 @@ public function testSession_regenerateSessionId_withLock_withDestroy_withProxy(
5468
5473
$ this ->assertEquals ('bar ' , $ this ->getSessionData ($ newSessionId ));
5469
5474
}
5470
5475
5476
+ public function testSession_ttl_equalsToSessionLifetime ()
5477
+ {
5478
+ $ sessionId = $ this ->generateSessionId ();
5479
+ $ this ->startSessionProcess ($ sessionId , 0 , false , 300 , true , null , -1 , 0 , 'test ' , 600 );
5480
+ $ ttl = $ this ->redis ->ttl ($ this ->sessionPrefix . $ sessionId );
5481
+
5482
+ $ this ->assertEquals (600 , $ ttl );
5483
+ }
5484
+
5485
+ public function testSession_ttl_resetOnWrite ()
5486
+ {
5487
+ $ sessionId = $ this ->generateSessionId ();
5488
+ $ this ->startSessionProcess ($ sessionId , 0 , false , 300 , true , null , -1 , 0 , 'test ' , 600 );
5489
+ $ this ->redis ->expire ($ this ->sessionPrefix . $ sessionId , 9999 );
5490
+ $ this ->startSessionProcess ($ sessionId , 0 , false , 300 , true , null , -1 , 0 , 'test ' , 600 );
5491
+ $ ttl = $ this ->redis ->ttl ($ this ->sessionPrefix . $ sessionId );
5492
+
5493
+ $ this ->assertEquals (600 , $ ttl );
5494
+ }
5495
+
5496
+ public function testSession_ttl_resetOnRead ()
5497
+ {
5498
+ $ sessionId = $ this ->generateSessionId ();
5499
+ $ this ->startSessionProcess ($ sessionId , 0 , false , 300 , true , null , -1 , 0 , 'test ' , 600 );
5500
+ $ this ->redis ->expire ($ this ->sessionPrefix . $ sessionId , 9999 );
5501
+ $ this ->getSessionData ($ sessionId , 600 );
5502
+ $ ttl = $ this ->redis ->ttl ($ this ->sessionPrefix . $ sessionId );
5503
+
5504
+ $ this ->assertEquals (600 , $ ttl );
5505
+ }
5506
+
5471
5507
private function setSessionHandler ()
5472
5508
{
5473
5509
$ host = $ this ->getHost () ?: 'localhost ' ;
5474
5510
5475
- ini_set ('session.save_handler ' , 'redis ' );
5476
- ini_set ('session.save_path ' , 'tcp:// ' . $ host . ':6379 ' );
5511
+ @ ini_set ('session.save_handler ' , 'redis ' );
5512
+ @ ini_set ('session.save_path ' , 'tcp:// ' . $ host . ':6379 ' );
5477
5513
}
5478
5514
5479
5515
/**
@@ -5503,15 +5539,18 @@ private function generateSessionId()
5503
5539
* @param int $lock_expires
5504
5540
* @param string $sessionData
5505
5541
*
5542
+ * @param int $sessionLifetime
5543
+ *
5506
5544
* @return bool
5545
+ * @throws Exception
5507
5546
*/
5508
- private function startSessionProcess ($ sessionId , $ sleepTime , $ background , $ maxExecutionTime = 300 , $ locking_enabled = true , $ lock_wait_time = null , $ lock_retries = -1 , $ lock_expires = 0 , $ sessionData = '' )
5547
+ private function startSessionProcess ($ sessionId , $ sleepTime , $ background , $ maxExecutionTime = 300 , $ locking_enabled = true , $ lock_wait_time = null , $ lock_retries = -1 , $ lock_expires = 0 , $ sessionData = '' , $ sessionLifetime = 1440 )
5509
5548
{
5510
5549
if (substr (php_uname (), 0 , 7 ) == "Windows " ){
5511
5550
$ this ->markTestSkipped ();
5512
5551
return true ;
5513
5552
} else {
5514
- $ commandParameters = array ($ this ->getHost (), $ sessionId , $ sleepTime , $ maxExecutionTime , $ lock_retries , $ lock_expires , $ sessionData );
5553
+ $ commandParameters = array ($ this ->getFullHostPath (), $ this -> sessionSaveHandler , $ sessionId , $ sleepTime , $ maxExecutionTime , $ lock_retries , $ lock_expires , $ sessionData, $ sessionLifetime );
5515
5554
if ($ locking_enabled ) {
5516
5555
$ commandParameters [] = '1 ' ;
5517
5556
@@ -5531,12 +5570,13 @@ private function startSessionProcess($sessionId, $sleepTime, $background, $maxEx
5531
5570
5532
5571
/**
5533
5572
* @param string $sessionId
5573
+ * @param int $sessionLifetime
5534
5574
*
5535
5575
* @return string
5536
5576
*/
5537
- private function getSessionData ($ sessionId )
5577
+ private function getSessionData ($ sessionId, $ sessionLifetime = 1440 )
5538
5578
{
5539
- $ command = 'php ' . __DIR__ . '/getSessionData.php ' . escapeshellarg ($ this ->getHost ()) . ' ' . escapeshellarg ($ sessionId );
5579
+ $ command = 'php ' . __DIR__ . '/getSessionData.php ' . escapeshellarg ($ this ->getFullHostPath ()) . ' ' . $ this -> sessionSaveHandler . ' ' . escapeshellarg ($ sessionId) . ' ' . escapeshellarg ( $ sessionLifetime );
5540
5580
exec ($ command , $ output );
5541
5581
5542
5582
return $ output [0 ];
@@ -5554,7 +5594,7 @@ private function regenerateSessionId($sessionId, $locking = false, $destroyPrevi
5554
5594
{
5555
5595
$ args = array_map ('escapeshellarg ' , array ($ sessionId , $ locking , $ destroyPrevious , $ sessionProxy ));
5556
5596
5557
- $ command = 'php --no-php-ini --define extension=igbinary.so --define extension= ' . __DIR__ . '/../modules/redis.so ' . __DIR__ . '/regenerateSessionId.php ' . escapeshellarg ($ this ->getHost ()) . ' ' . implode (' ' , $ args );
5597
+ $ command = 'php --no-php-ini --define extension=igbinary.so --define extension= ' . __DIR__ . '/../modules/redis.so ' . __DIR__ . '/regenerateSessionId.php ' . escapeshellarg ($ this ->getFullHostPath ()) . ' ' . $ this -> sessionSaveHandler . ' ' . implode (' ' , $ args );
5558
5598
5559
5599
exec ($ command , $ output );
5560
5600
0 commit comments