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
297297 // so we need to check here if the lock key is for the
298298 // correct session ID.
299299 if ($ this ->lockKey === $ lockKey ) {
300+ // If there is the lock, make the ttl longer.
300301 return $ this ->redis ->expire ($ this ->lockKey , 300 );
301302 }
302303
303304 $ attempt = 0 ;
304305
305306 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+ );
308314
309- if ($ ttl > 0 ) {
310- sleep ( 1 );
315+ if (! $ result ) {
316+ usleep ( 100000 );
311317
312318 continue ;
313319 }
314320
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-
323321 $ this ->lockKey = $ lockKey ;
324322 break ;
325- } while (++$ attempt < 30 );
323+ } while (++$ attempt < 300 );
326324
327- if ($ attempt === 30 ) {
325+ if ($ attempt === 300 ) {
328326 $ 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. '
330329 );
331330
332331 return false ;
333332 }
334333
335- if ($ ttl === -1 ) {
336- $ this ->logger ->debug (
337- 'Session: Lock for ' . $ this ->keyPrefix . $ sessionID . ' had no TTL, overriding. '
338- );
339- }
340-
341334 $ this ->lock = true ;
342335
343336 return true ;
You can’t perform that action at this time.
0 commit comments