Skip to content

Fix getRequestStartTime for Octane workers#43

Open
m0nclous wants to merge 1 commit intobeyondcode:masterfrom
m0nclous:master
Open

Fix getRequestStartTime for Octane workers#43
m0nclous wants to merge 1 commit intobeyondcode:masterfrom
m0nclous:master

Conversation

@m0nclous
Copy link
Copy Markdown

Fix defining $this->start via getRequestStartTime() for Laravel Octane workers
#37

Problem

Under Laravel Octane (Swoole/RoadRunner/FrankenPHP), worker processes are persistent and handle multiple requests during their lifetime. The previous implementation relied on $_SERVER['REQUEST_TIME_FLOAT'] and the LARAVEL_START constant, both of which are set once at worker initialization and never updated between requests.

This caused $this->start to always reflect the start time of the first request handled by the worker, making all subsequent server timing measurements incorrect.

Solution

Use request()->server('REQUEST_TIME_FLOAT') instead, which reads from the current request context that Octane properly resets on each request.

The LARAVEL_START constant is still used as a fallback for non-Octane environments where $_SERVER and constants behave as expected.

Changes

  • getRequestStartTime() now checks for LARAVEL_OCTANE in the request context to determine the runtime environment
  • Replaced $_SERVER superglobal with request()->server() for Octane compatibility
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants