File tree Expand file tree Collapse file tree 1 file changed +14
-21
lines changed Expand file tree Collapse file tree 1 file changed +14
-21
lines changed Original file line number Diff line number Diff line change @@ -297,47 +297,40 @@ protected function lockSession(string $sessionID): bool
297
297
// so we need to check here if the lock key is for the
298
298
// correct session ID.
299
299
if ($ this ->lockKey === $ lockKey ) {
300
+ // If there is the lock, make the ttl longer.
300
301
return $ this ->redis ->expire ($ this ->lockKey , 300 );
301
302
}
302
303
303
304
$ attempt = 0 ;
304
305
305
306
do {
306
- $ ttl = $ this ->redis ->ttl ($ lockKey );
307
- assert (is_int ($ ttl ));
307
+ $ result = $ this ->redis ->set (
308
+ $ lockKey ,
309
+ (string ) Time::now ()->getTimestamp (),
310
+ // NX -- Only set the key if it does not already exist.
311
+ // EX seconds -- Set the specified expire time, in seconds.
312
+ ['nx ' , 'ex ' => 300 ]
313
+ );
308
314
309
- if ($ ttl > 0 ) {
310
- sleep ( 1 );
315
+ if (! $ result ) {
316
+ usleep ( 100000 );
311
317
312
318
continue ;
313
319
}
314
320
315
- if (! $ this ->redis ->setex ($ lockKey , 300 , (string ) Time::now ()->getTimestamp ())) {
316
- $ this ->logger ->error (
317
- 'Session: Error while trying to obtain lock for ' . $ this ->keyPrefix . $ sessionID
318
- );
319
-
320
- return false ;
321
- }
322
-
323
321
$ this ->lockKey = $ lockKey ;
324
322
break ;
325
- } while (++$ attempt < 30 );
323
+ } while (++$ attempt < 300 );
326
324
327
- if ($ attempt === 30 ) {
325
+ if ($ attempt === 300 ) {
328
326
$ this ->logger ->error (
329
- 'Session: Unable to obtain lock for ' . $ this ->keyPrefix . $ sessionID . ' after 30 attempts, aborting. '
327
+ 'Session: Unable to obtain lock for ' . $ this ->keyPrefix . $ sessionID
328
+ . ' after 300 attempts, aborting. '
330
329
);
331
330
332
331
return false ;
333
332
}
334
333
335
- if ($ ttl === -1 ) {
336
- $ this ->logger ->debug (
337
- 'Session: Lock for ' . $ this ->keyPrefix . $ sessionID . ' had no TTL, overriding. '
338
- );
339
- }
340
-
341
334
$ this ->lock = true ;
342
335
343
336
return true ;
You can’t perform that action at this time.
0 commit comments