Skip to content

[PHP] Use a contextual SAPI name #2424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open

[PHP] Use a contextual SAPI name #2424

wants to merge 7 commits into from

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Jul 25, 2025

Motivation for the change, related issues

Uses a relevant SAPI name for the current execution context:

  • cli for CLI scripts
  • playground for everything else

We've been struggling with the SAPI name for a while now. Some tools, like WP-CLI, expect the SAPI name to be cli – so we've hardcoded that. However, that broke other tools, such as the query-monitor plugin, that expect the SAPI name NOT to be cli.

Before this PR we could only set the SAPI name once – before the first PHP code execution. With this PR, we can set it at any point.

Implementation details

This PR ships a set_sapi_name( $new_name ) PHP function that updates the value returned by php_sapi_name() function and the PHP_SAPI constant.

Why a PHP runtime function? It's more convenient than controlling that from the TypeScript runtime via php.setSapiName(). We only need to maintain a single code path where we know the PHP runtime was already initialized. There's no need to check what if we're before the first code execution? Or what if we've trashed the runtime already? Or what do we do after the runtime hotswapping?

The .setSapiName() now sets the PLAYGROUND_SAPI_NAME constant, and the set_sapi_name() function is always called in the auto_prepend_file script with the current PLAYGROUND_SAPI_NAME constant value.

Testing Instructions (or ideally a Blueprint)

@adamziel
Copy link
Collaborator Author

@johnbillion this PR will enable removing the recent query-monitor workaround

@adamziel adamziel requested a review from a team as a code owner July 26, 2025 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant