refactor: cgi strings by AlliBalliBaba · Pull Request #2188 · php/frankenphp

Choose a reason for hiding this comment

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

Pull request overview

Refactors how CGI/$_SERVER string keys are managed by moving hard-coded zend_string keys into a C-side interned-strings struct, reducing Go-side map lookups/allocations and enabling more efficient $_SERVER sizing during registration.

Changes:

  • Introduces C-side interned string registry (frankenphp_strings) and a frankenphp_server_vars struct to bulk-register known $_SERVER variables with pre-sized hashtable capacity.
  • Simplifies Go-side CGI/server-variable registration to rely on C-side known keys, keeping only the common-header cache map in Go.
  • Minor header handling refactor in Go to pass sapi_header_struct directly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
phpmainthread.go Moves common header zend_string cache to a package-global map and initializes it once.
frankenphp.h Defines frankenphp_server_vars and frankenphp_strings interned-string registry; updates exported APIs.
frankenphp.go Adjusts header parsing helper to accept sapi_header_struct.
frankenphp.c Implements interned-string initialization, server var bulk registration, and updates request variable registration flow.
env.go Captures OS env count for $_SERVER pre-sizing; switches to newPersistentZendString.
cgi.go Reworks known CGI var registration to use C-side interned keys/values; adds tlsProtocol and helper wrappers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.