[PHP] Use a contextual SAPI name - #2424
Conversation
|
@johnbillion this PR will enable removing the recent query-monitor workaround |
|
Since we're now capable of running the CLI SAPI and the embed SAPI as needed, this PR is no longer necessary. In fact, we should remove the |
|
@adamziel JFYI, in Studio we faced this issue and we are going to use the same workaround for consistency (with setting I didn't get what it means - |
Fix comment for Query Monitor plugin temporary fix: - Introduced in c31863e via Automattic#2080 & WordPress/wordpress-playground#2424
Motivation for the change, related issues
Uses a relevant SAPI name for the current execution context:
clifor CLI scriptsplaygroundfor everything elseWe'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 becli.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 byphp_sapi_name()function and thePHP_SAPIconstant.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 thePLAYGROUND_SAPI_NAMEconstant, and theset_sapi_name()function is always called in theauto_prepend_filescript with the currentPLAYGROUND_SAPI_NAMEconstant value.Testing Instructions (or ideally a Blueprint)