From 7f66891e940d5cfaf358094705f8237deb709708 Mon Sep 17 00:00:00 2001 From: Kieran Brahney Date: Mon, 23 Oct 2023 12:26:39 +0100 Subject: [PATCH 1/2] [10.x] Ability to configure default session block timeouts --- .../Session/Middleware/StartSession.php | 4 ++-- src/Illuminate/Session/SessionManager.php | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Session/Middleware/StartSession.php b/src/Illuminate/Session/Middleware/StartSession.php index 8079ab9c145a..1ecf78fdbd13 100644 --- a/src/Illuminate/Session/Middleware/StartSession.php +++ b/src/Illuminate/Session/Middleware/StartSession.php @@ -80,7 +80,7 @@ protected function handleRequestWhileBlocking(Request $request, $session, Closur $lockFor = $request->route() && $request->route()->locksFor() ? $request->route()->locksFor() - : 10; + : $this->manager->blocksFor(); $lock = $this->cache($this->manager->blockDriver()) ->lock('session:'.$session->getId(), $lockFor) @@ -90,7 +90,7 @@ protected function handleRequestWhileBlocking(Request $request, $session, Closur $lock->block( ! is_null($request->route()->waitsFor()) ? $request->route()->waitsFor() - : 10 + : $this->manager->waitsFor() ); return $this->handleStatefulRequest($request, $session, $next); diff --git a/src/Illuminate/Session/SessionManager.php b/src/Illuminate/Session/SessionManager.php index 01112f01ecbf..a41aff55a521 100755 --- a/src/Illuminate/Session/SessionManager.php +++ b/src/Illuminate/Session/SessionManager.php @@ -226,6 +226,26 @@ public function shouldBlock() return $this->config->get('session.block', false); } + /** + * Get the maximum number of seconds the session lock should be held for. + * + * @return int + */ + public function blocksFor() + { + return $this->config->get('session.block__lock_timeout', 10); + } + + /** + * Get the maximum number of seconds to wait while attempting to acquire a session lock. + * + * @return int + */ + public function waitsFor() + { + return $this->config->get('session.block_wait_timeout', 10); + } + /** * Get the name of the cache store / driver that should be used to acquire session locks. * From 63fff6bcceb16abe9908faecf1d40e2b314915b5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 26 Oct 2023 09:32:56 -0500 Subject: [PATCH 2/2] formatting --- .../Session/Middleware/StartSession.php | 4 ++-- src/Illuminate/Session/SessionManager.php | 22 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Illuminate/Session/Middleware/StartSession.php b/src/Illuminate/Session/Middleware/StartSession.php index 1ecf78fdbd13..53f3a16c6ba2 100644 --- a/src/Illuminate/Session/Middleware/StartSession.php +++ b/src/Illuminate/Session/Middleware/StartSession.php @@ -80,7 +80,7 @@ protected function handleRequestWhileBlocking(Request $request, $session, Closur $lockFor = $request->route() && $request->route()->locksFor() ? $request->route()->locksFor() - : $this->manager->blocksFor(); + : $this->manager->defaultRouteBlockLockSeconds(); $lock = $this->cache($this->manager->blockDriver()) ->lock('session:'.$session->getId(), $lockFor) @@ -90,7 +90,7 @@ protected function handleRequestWhileBlocking(Request $request, $session, Closur $lock->block( ! is_null($request->route()->waitsFor()) ? $request->route()->waitsFor() - : $this->manager->waitsFor() + : $this->manager->defaultRouteBlockWaitSeconds() ); return $this->handleStatefulRequest($request, $session, $next); diff --git a/src/Illuminate/Session/SessionManager.php b/src/Illuminate/Session/SessionManager.php index a41aff55a521..6094627e6ef5 100755 --- a/src/Illuminate/Session/SessionManager.php +++ b/src/Illuminate/Session/SessionManager.php @@ -227,33 +227,33 @@ public function shouldBlock() } /** - * Get the maximum number of seconds the session lock should be held for. + * Get the name of the cache store / driver that should be used to acquire session locks. * - * @return int + * @return string|null */ - public function blocksFor() + public function blockDriver() { - return $this->config->get('session.block__lock_timeout', 10); + return $this->config->get('session.block_store'); } /** - * Get the maximum number of seconds to wait while attempting to acquire a session lock. + * Get the maximum number of seconds the session lock should be held for. * * @return int */ - public function waitsFor() + public function defaultRouteBlockLockSeconds() { - return $this->config->get('session.block_wait_timeout', 10); + return $this->config->get('session.block_lock_seconds', 10); } /** - * Get the name of the cache store / driver that should be used to acquire session locks. + * Get the maximum number of seconds to wait while attempting to acquire a route block session lock. * - * @return string|null + * @return int */ - public function blockDriver() + public function defaultRouteBlockWaitSeconds() { - return $this->config->get('session.block_store'); + return $this->config->get('session.block_wait_seconds', 10); } /**