fix: don't flush env between requests by AlliBalliBaba · Pull Request #1814 · php/frankenphp

@AlliBalliBaba

This is an alternative to #1799 that instead doesn't flush the $_ENV global at all. I realized that the 'default' state of globals is just a bunch of 0 bits. I also realized that worker mode currently doesn't support $_REQUEST.

cc @withinboredom can you check if this also fixes the segfaults you have been seeing?

@AlliBalliBaba

I just now also realized that it's not even necessary to flush globals. Their re-import will flush them anyways.

Only $_FILES needs to be flushed or it will segfault, still curious why.

Also surprised that noone has so far complained about $_REQUEST not being supported in worker mode. It will only work if it's jit is disabled.

@AlliBalliBaba

@AlliBalliBaba

@AlliBalliBaba

Alright, I think I finally figured out a cleaner way to reset globals.

Insterestingly, only $FILES will not be flushed on import, all other globals are flushed.
see: $_GET $_POST $_COOKIE $_SERVER $_ENV $_FILES $_REQUEST

I think it might make sense to document that $_REQUEST is only supported in worker mode if auto_globals_jit = Off (unrelated to this PR).

dunglas

Choose a reason for hiding this comment

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

LGTM. Is it ready to be merged?

withinboredom

# Conflicts:
#	frankenphp.c

@AlliBalliBaba

@AlliBalliBaba

Just merged main, should be good to go if CI is green

@AlliBalliBaba

Watcher tests seem to be failing right now (maybe an update?), I'll have a look

@AlliBalliBaba

@AlliBalliBaba

Nvm, rather it looks like the phpheaders_test (#1823) will still randomly fail builds so I moved it back to frankenphp_test (probably will report this one to go)

@AlliBalliBaba

Should be fine now 👍 , linting failure is unrelated to this PR.

dunglas

@AlliBalliBaba

dunglas

@dunglas dunglas deleted the fix/dont-flush-env-between-requests branch

August 27, 2025 06:30

@dunglas

Thank you! Great work, as usual.

henderkes pushed a commit to static-php/frankenphp that referenced this pull request

Sep 11, 2025

@AlliBalliBaba @henderkes