Skip to content

AOT: deferred header() flush uses write(2) before body (#634) - #36154

Merged
PurHur merged 1 commit into
masterfrom
fix/aot-deferred-header-flush-write
Sep 1, 2026
Merged

AOT: deferred header() flush uses write(2) before body (#634)#36154
PurHur merged 1 commit into
masterfrom
fix/aot-deferred-header-flush-write

Conversation

@PurHur

@PurHur PurHur commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fix AOT CGI header ordering for header() + echo json_encode(...) web fixtures: __phpc_response_headers_flush now emits Status/header lines with write(2) instead of printf(3), so deferred headers are not stuck in the stdio buffer while body output uses direct write(2).
  • Gate CGI stdout emission on getenv('REQUEST_METHOD') (CLI headers_list cases stay quiet).
  • Do not mark the pending-header queue flushed when a flush pass wrote nothing; invalidate the LLVM header mirror on header_remove() so removed lines are not replayed.

php-src reference: ext/standard/head.c (sapi header emit before body).

Closes #634

Test plan

./script/aot-smoke.sh
# aot-smoke: 8 passed, 0 failed

./script/phpunit.sh --filter 'json_encode_api|echo_header_before_body|class_method_json_api|header_remove|headers_list'
# OK (8 tests, 35 assertions) — primary json/header ordering cases green

Not covered: full AotTest header filter (some cases like setcookie_headers_list segfault on master too), differential sweep, self-host gates.

Made with Cursor

printf(3) stayed in the stdio buffer while echo used write(2), so CGI
Status/Content-Type appeared after the JSON body. Flush now uses write,
skips CLI runs without REQUEST_METHOD, avoids marking flushed on empty
no-ops, and invalidates the LLVM header mirror on header_remove().

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 15f66f9 into master Sep 1, 2026
1 check failed
@PurHur
PurHur deleted the fix/aot-deferred-header-flush-write branch September 1, 2026 09:04
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.

Web: header() Location redirect (302) for VM, JIT, and AOT

1 participant