Skip to content

Fix getRequestStartTime for Octane workers#43

Open
m0nclous wants to merge 1 commit into
beyondcode:masterfrom
m0nclous:master
Open

Fix getRequestStartTime for Octane workers#43
m0nclous wants to merge 1 commit into
beyondcode: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

@ulcuber ulcuber left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs $this->app->scoped(ServerTiming...); instead of singletone to prevent $finishedEvents and stopwatches collision

@ulcuber

ulcuber commented Jun 18, 2026

Copy link
Copy Markdown

Great hack. Much better than hooking Octane's RequestReceived. The most accurate. I cannot find any better place from swoole-server to RequestReceived event that could allow hook into

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.

3 participants