waitForWorkerRequest is called during frankenphp_handle_request in the php worker script.
()
| 204 | |
| 205 | // waitForWorkerRequest is called during frankenphp_handle_request in the php worker script. |
| 206 | func (handler *workerThread) waitForWorkerRequest() (bool, any) { |
| 207 | // unpin any memory left over from previous requests |
| 208 | handler.thread.Unpin() |
| 209 | |
| 210 | if globalLogger.Enabled(globalCtx, slog.LevelDebug) { |
| 211 | globalLogger.LogAttrs(globalCtx, slog.LevelDebug, "waiting for request", slog.String("worker", handler.worker.name), slog.Int("thread", handler.thread.threadIndex)) |
| 212 | } |
| 213 | |
| 214 | // Clear the first dummy request created to initialize the worker |
| 215 | if handler.isBootingScript { |
| 216 | handler.isBootingScript = false |
| 217 | handler.failureCount = 0 |
| 218 | if !C.frankenphp_shutdown_dummy_request() { |
| 219 | panic("Not in CGI context") |
| 220 | } |
| 221 | |
| 222 | // worker is truly ready only after reaching frankenphp_handle_request() |
| 223 | metrics.ReadyWorker(handler.worker.name) |
| 224 | } |
| 225 | |
| 226 | // max_requests reached: signal reboot for full ZTS cleanup |
| 227 | if maxRequestsPerThread > 0 && handler.requestCount >= maxRequestsPerThread { |
| 228 | if globalLogger.Enabled(globalCtx, slog.LevelDebug) { |
| 229 | globalLogger.LogAttrs(globalCtx, slog.LevelDebug, "max requests reached, restarting", |
| 230 | slog.String("worker", handler.worker.name), |
| 231 | slog.Int("thread", handler.thread.threadIndex), |
| 232 | slog.Int("max_requests", maxRequestsPerThread), |
| 233 | ) |
| 234 | } |
| 235 | |
| 236 | if handler.thread.reboot() { |
| 237 | return false, nil |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | if handler.state.Is(state.TransitionComplete) { |
| 242 | handler.state.Set(state.Ready) |
| 243 | } |
| 244 | |
| 245 | handler.state.MarkAsWaiting(true) |
| 246 | |
| 247 | var requestCH contextHolder |
| 248 | select { |
| 249 | case <-handler.thread.drainChan: |
| 250 | if globalLogger.Enabled(globalCtx, slog.LevelDebug) { |
| 251 | globalLogger.LogAttrs(globalCtx, slog.LevelDebug, "shutting down", slog.String("worker", handler.worker.name), slog.Int("thread", handler.thread.threadIndex)) |
| 252 | } |
| 253 | |
| 254 | // flush the opcache when restarting due to watcher or admin api |
| 255 | // note: this is done right before frankenphp_handle_request() returns 'false' |
| 256 | if handler.state.Is(state.Restarting) { |
| 257 | C.frankenphp_reset_opcache() |
| 258 | } |
| 259 | |
| 260 | return false, nil |
| 261 | case requestCH = <-handler.thread.requestChan: |
| 262 | case requestCH = <-handler.worker.requestChan: |
| 263 | } |
no test coverage detected