ServeHTTP executes a PHP script according to the given context.
(responseWriter http.ResponseWriter, request *http.Request)
| 390 | |
| 391 | // ServeHTTP executes a PHP script according to the given context. |
| 392 | func ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error { |
| 393 | h := responseWriter.Header() |
| 394 | if h["Server"] == nil { |
| 395 | h["Server"] = serverHeader |
| 396 | } |
| 397 | |
| 398 | if !isRunning { |
| 399 | return ErrNotRunning |
| 400 | } |
| 401 | |
| 402 | ctx := request.Context() |
| 403 | fc, ok := fromContext(ctx) |
| 404 | |
| 405 | ch := contextHolder{ctx, fc} |
| 406 | |
| 407 | if !ok { |
| 408 | return ErrInvalidRequest |
| 409 | } |
| 410 | |
| 411 | fc.responseWriter = responseWriter |
| 412 | |
| 413 | if err := fc.validate(); err != nil { |
| 414 | return err |
| 415 | } |
| 416 | |
| 417 | // Detect if a worker is available to handle this request |
| 418 | if fc.worker != nil { |
| 419 | return fc.worker.handleRequest(ch) |
| 420 | } |
| 421 | |
| 422 | // If no worker was available, send the request to non-worker threads |
| 423 | return handleRequestWithRegularPHPThreads(ch) |
| 424 | } |
| 425 | |
| 426 | //export go_ub_write |
| 427 | func go_ub_write(threadIndex C.uintptr_t, cBuf *C.char, length C.size_t) (C.size_t, C.bool) { |