Skip to content

Commit 86d9436

Browse files
authored
Update timers.md
1 parent fa7cf54 commit 86d9436

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

docs/features/timers.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,12 @@ class MyWorkflow extends Workflow
2929

3030
You may also specify the time to wait as a string e.g. '5 seconds' or '30 minutes'.
3131

32-
**Important:** When using timers, you should not use the `Carbon::now()` method to get the current time. Instead, you should use the `WorkflowStub::now()` method, which will return the current time as seen by the workflow system. This is important because the actual time may not match the time as seen by your application. When comparing timestamps in workflows (e.g., timing how long an operation takes), always use `WorkflowStub::sideEffect(fn () => WorkflowStub::now())` instead of directly calling `WorkflowStub::now()`. This ensures the timestamp remains consistent across workflow replay.
32+
**Important:** When using timers, do not use `Carbon::now()` to get the current time. Instead, use `WorkflowStub::now()`, which returns the current time as seen by the workflow system. This is crucial because the actual time may not match your application's system clock.
33+
34+
Additionally, when measuring elapsed time in workflows (e.g., tracking how long an operation takes), always get your start time with:
35+
36+
```php
37+
$start = yield WorkflowStub::sideEffect(fn () => WorkflowStub::now());
38+
```
39+
40+
This ensures a checkpoint is created, preventing replay-related inconsistencies and guaranteeing accurate time calculations.

0 commit comments

Comments
 (0)