From e0d2316939ebbdcb8f3a11f4594fd2996ace2c35 Mon Sep 17 00:00:00 2001 From: smknstd Date: Tue, 18 Feb 2025 11:44:57 +0100 Subject: [PATCH 1/2] init new Timebox section --- helpers.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/helpers.md b/helpers.md index 66691c59da..51ae3fd5ed 100644 --- a/helpers.md +++ b/helpers.md @@ -9,6 +9,7 @@ - [Lottery](#lottery) - [Pipeline](#pipeline) - [Sleep](#sleep) + - [Timebox](#timebox) ## Introduction @@ -2769,3 +2770,20 @@ $start->diffForHumans(); // 1 second ago ``` Laravel uses the `Sleep` class internally whenever it is pausing execution. For example, the [`retry`](#method-retry) helper uses the `Sleep` class when sleeping, allowing for improved testability when using that helper. + + +### Timebox + +Laravel's `Timebox` ensure that the given callback always takes a fixed amount of time to execute, even if its actual execution completes sooner. This is particularly useful for cryptographic operations and user authentication checks, where attackers might exploit variations in execution time to infer sensitive information. If the execution exceeds the fixed duration, `Timebox` has no effect. It is up to the developer to choose a sufficiently long time as the fixed duration to account for worst-case scenarios. + +The call method accepts a closure and a time limit in microseconds, and then executes and waits until the time limit is reached. + + use Illuminate\Support\Timebox; + + (new Timebox)->call(function ($timebox) { + + // ... + + }, microseconds: 10000); + +If an exception is thrown within its callback, this class will respect the defined delay and rethrow the exception after the delay. \ No newline at end of file From 1b7c3f2d340865b7a0e60f368054385f2fe6b047 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 18 Feb 2025 09:28:56 -0600 Subject: [PATCH 2/2] formatting --- helpers.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/helpers.md b/helpers.md index 51ae3fd5ed..d7c6ad6538 100644 --- a/helpers.md +++ b/helpers.md @@ -2774,16 +2774,16 @@ Laravel uses the `Sleep` class internally whenever it is pausing execution. For ### Timebox -Laravel's `Timebox` ensure that the given callback always takes a fixed amount of time to execute, even if its actual execution completes sooner. This is particularly useful for cryptographic operations and user authentication checks, where attackers might exploit variations in execution time to infer sensitive information. If the execution exceeds the fixed duration, `Timebox` has no effect. It is up to the developer to choose a sufficiently long time as the fixed duration to account for worst-case scenarios. +Laravel's `Timebox` class ensures that the given callback always takes a fixed amount of time to execute, even if its actual execution completes sooner. This is particularly useful for cryptographic operations and user authentication checks, where attackers might exploit variations in execution time to infer sensitive information. -The call method accepts a closure and a time limit in microseconds, and then executes and waits until the time limit is reached. +If the execution exceeds the fixed duration, `Timebox` has no effect. It is up to the developer to choose a sufficiently long time as the fixed duration to account for worst-case scenarios. + +The call method accepts a closure and a time limit in microseconds, and then executes the closure and waits until the time limit is reached: use Illuminate\Support\Timebox; (new Timebox)->call(function ($timebox) { - // ... - }, microseconds: 10000); -If an exception is thrown within its callback, this class will respect the defined delay and rethrow the exception after the delay. \ No newline at end of file +If an exception is thrown within the closure, this class will respect the defined delay and re-throw the exception after the delay.