12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package frankenphp
- import (
- "net/http"
- "time"
- )
- type ThreadDebugState struct {
- Index int
- Name string
- State string
- IsHandlingRequest bool
- Path string
- InRequestSinceMilliseconds int64
- WaitingSinceMilliseconds int64
- }
- type FrankenPHPDebugState struct {
- ThreadDebugStates []ThreadDebugState
- ReservedThreadCount int
- }
- // EXPERIMENTAL: DebugState prints the state of all PHP threads - debugging purposes only
- func DebugState() FrankenPHPDebugState {
- fullState := FrankenPHPDebugState{
- ThreadDebugStates: make([]ThreadDebugState, 0, len(phpThreads)),
- ReservedThreadCount: 0,
- }
- for _, thread := range phpThreads {
- if thread.state.is(stateReserved) {
- fullState.ReservedThreadCount++
- continue
- }
- fullState.ThreadDebugStates = append(fullState.ThreadDebugStates, threadDebugState(thread))
- }
- return fullState
- }
- // threadDebugState creates a small jsonable status message for debugging purposes
- func threadDebugState(thread *phpThread) ThreadDebugState {
- debugState := ThreadDebugState{
- Index: thread.threadIndex,
- Name: thread.handler.name(),
- State: thread.state.name(),
- WaitingSinceMilliseconds: thread.state.waitTime(),
- }
- var r *http.Request
- if r = thread.getActiveRequestSafely(); r == nil {
- return debugState
- }
- fc := r.Context().Value(contextKey).(*FrankenPHPContext)
- if fc.originalRequest != nil {
- debugState.Path = fc.originalRequest.URL.Path
- } else {
- debugState.Path = r.URL.Path
- }
- if fc.responseWriter != nil {
- debugState.IsHandlingRequest = true
- debugState.InRequestSinceMilliseconds = time.Since(fc.startedAt).Milliseconds()
- }
- return debugState
- }
|