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

Draft
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,88 +4,83 @@ All notable changes to this project are documented in this file by a CI job
that runs on every NPM release. The file follows the [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
format.

## [v2.0.4] (2025-07-25)
## [v2.0.4] (2025-07-25)

### Public API


#### Blueprints

- Distribute @wp-playground/client without any package.json dependencies. ([#2426](https://github.com/WordPress/wordpress-playground/pull/2426))
- Distribute @wp-playground/client without any package.json dependencies. ([#2426](https://github.com/WordPress/wordpress-playground/pull/2426))

### Tools

- Fix ESLint 9 linting in VSCode. ([#2417](https://github.com/WordPress/wordpress-playground/pull/2417))
- [ xdebug ] Add `--experimental-devtools` option in Playground CLI. ([#2411](https://github.com/WordPress/wordpress-playground/pull/2411))
- Fix ESLint 9 linting in VSCode. ([#2417](https://github.com/WordPress/wordpress-playground/pull/2417))
- [ xdebug ] Add `--experimental-devtools` option in Playground CLI. ([#2411](https://github.com/WordPress/wordpress-playground/pull/2411))

### PHP WebAssembly

- [PHP] Dispatch request.error for all non-zero-exit request handler errors. ([#2429](https://github.com/WordPress/wordpress-playground/pull/2429))
- [PHP] Dispatch request.error for all non-zero-exit request handler errors. ([#2429](https://github.com/WordPress/wordpress-playground/pull/2429))

### Website

- Query Monitor plugin support. ([#2415](https://github.com/WordPress/wordpress-playground/pull/2415))
- Query Monitor plugin support. ([#2415](https://github.com/WordPress/wordpress-playground/pull/2415))

### Internal

- Skip flaky end-to-end tests in Firefox and Webkit. ([#2425](https://github.com/WordPress/wordpress-playground/pull/2425))
- Skip flaky end-to-end tests in Firefox and Webkit. ([#2425](https://github.com/WordPress/wordpress-playground/pull/2425))

### Bug Fixes

- [Xdebug Bridge] Correct error related to unresolved promises in bridge. ([#2422](https://github.com/WordPress/wordpress-playground/pull/2422))
- [Xdebug Bridge] Correct error related to unresolved promises in bridge. ([#2422](https://github.com/WordPress/wordpress-playground/pull/2422))

### Various

- Documentation add sidebar to blueprints bundles. ([#2397](https://github.com/WordPress/wordpress-playground/pull/2397))
- Documentation add sidebar to blueprints bundles. ([#2397](https://github.com/WordPress/wordpress-playground/pull/2397))

### Contributors

The following contributors merged PRs in this release:

@adamziel @brandonpayton @mho22 @shimotmk


## [v2.0.3] (2025-07-24)
## [v2.0.3] (2025-07-24)

### Tools

- [ xdebug ] Add `--experimental-devtools` option in php-wasm CLI. ([#2408](https://github.com/WordPress/wordpress-playground/pull/2408))
- [ xdebug ] Add `--experimental-devtools` option in php-wasm CLI. ([#2408](https://github.com/WordPress/wordpress-playground/pull/2408))

### Bug Fixes

- Playground CLI Allow /wordpress subdirs to be mounted before WP install. ([#2382](https://github.com/WordPress/wordpress-playground/pull/2382))
- Playground CLI Allow /wordpress subdirs to be mounted before WP install. ([#2382](https://github.com/WordPress/wordpress-playground/pull/2382))

### Contributors

The following contributors merged PRs in this release:

@brandonpayton @mho22


## [v2.0.2] (2025-07-23)
## [v2.0.2] (2025-07-23)

### Tools


#### PHP WebAssembly

- [ xdebug ] Bridge DBGP session with CDP server. ([#2402](https://github.com/WordPress/wordpress-playground/pull/2402))
- [ xdebug ] Bridge DBGP session with CDP server. ([#2402](https://github.com/WordPress/wordpress-playground/pull/2402))

### Internal

- [Build] Preserve optionalDependencies in built package.json. ([#2410](https://github.com/WordPress/wordpress-playground/pull/2410))
- [Build] Preserve optionalDependencies in built package.json. ([#2410](https://github.com/WordPress/wordpress-playground/pull/2410))

###
###

- Comlink] Throw the original error in the error handler. ([#2407](https://github.com/WordPress/wordpress-playground/pull/2407))
- Comlink] Throw the original error in the error handler. ([#2407](https://github.com/WordPress/wordpress-playground/pull/2407))

### Contributors

The following contributors merged PRs in this release:

@adamziel


## [v2.0.1] (2025-07-23)

### Blueprints
Expand Down
39 changes: 17 additions & 22 deletions packages/docs/site/docs/main/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,88 +9,83 @@ All notable changes to this project are documented in this file by a CI job
that runs on every NPM release. The file follows the [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
format.

## [v2.0.4] (2025-07-25)
## [v2.0.4] (2025-07-25)

### Public API


#### Blueprints

- Distribute @wp-playground/client without any package.json dependencies. ([#2426](https://github.com/WordPress/wordpress-playground/pull/2426))
- Distribute @wp-playground/client without any package.json dependencies. ([#2426](https://github.com/WordPress/wordpress-playground/pull/2426))

### Tools

- Fix ESLint 9 linting in VSCode. ([#2417](https://github.com/WordPress/wordpress-playground/pull/2417))
- [ xdebug ] Add `--experimental-devtools` option in Playground CLI. ([#2411](https://github.com/WordPress/wordpress-playground/pull/2411))
- Fix ESLint 9 linting in VSCode. ([#2417](https://github.com/WordPress/wordpress-playground/pull/2417))
- [ xdebug ] Add `--experimental-devtools` option in Playground CLI. ([#2411](https://github.com/WordPress/wordpress-playground/pull/2411))

### PHP WebAssembly

- [PHP] Dispatch request.error for all non-zero-exit request handler errors. ([#2429](https://github.com/WordPress/wordpress-playground/pull/2429))
- [PHP] Dispatch request.error for all non-zero-exit request handler errors. ([#2429](https://github.com/WordPress/wordpress-playground/pull/2429))

### Website

- Query Monitor plugin support. ([#2415](https://github.com/WordPress/wordpress-playground/pull/2415))
- Query Monitor plugin support. ([#2415](https://github.com/WordPress/wordpress-playground/pull/2415))

### Internal

- Skip flaky end-to-end tests in Firefox and Webkit. ([#2425](https://github.com/WordPress/wordpress-playground/pull/2425))
- Skip flaky end-to-end tests in Firefox and Webkit. ([#2425](https://github.com/WordPress/wordpress-playground/pull/2425))

### Bug Fixes

- [Xdebug Bridge] Correct error related to unresolved promises in bridge. ([#2422](https://github.com/WordPress/wordpress-playground/pull/2422))
- [Xdebug Bridge] Correct error related to unresolved promises in bridge. ([#2422](https://github.com/WordPress/wordpress-playground/pull/2422))

### Various

- Documentation add sidebar to blueprints bundles. ([#2397](https://github.com/WordPress/wordpress-playground/pull/2397))
- Documentation add sidebar to blueprints bundles. ([#2397](https://github.com/WordPress/wordpress-playground/pull/2397))

### Contributors

The following contributors merged PRs in this release:

@adamziel @brandonpayton @mho22 @shimotmk


## [v2.0.3] (2025-07-24)
## [v2.0.3] (2025-07-24)

### Tools

- [ xdebug ] Add `--experimental-devtools` option in php-wasm CLI. ([#2408](https://github.com/WordPress/wordpress-playground/pull/2408))
- [ xdebug ] Add `--experimental-devtools` option in php-wasm CLI. ([#2408](https://github.com/WordPress/wordpress-playground/pull/2408))

### Bug Fixes

- Playground CLI Allow /wordpress subdirs to be mounted before WP install. ([#2382](https://github.com/WordPress/wordpress-playground/pull/2382))
- Playground CLI Allow /wordpress subdirs to be mounted before WP install. ([#2382](https://github.com/WordPress/wordpress-playground/pull/2382))

### Contributors

The following contributors merged PRs in this release:

@brandonpayton @mho22


## [v2.0.2] (2025-07-23)
## [v2.0.2] (2025-07-23)

### Tools


#### PHP WebAssembly

- [ xdebug ] Bridge DBGP session with CDP server. ([#2402](https://github.com/WordPress/wordpress-playground/pull/2402))
- [ xdebug ] Bridge DBGP session with CDP server. ([#2402](https://github.com/WordPress/wordpress-playground/pull/2402))

### Internal

- [Build] Preserve optionalDependencies in built package.json. ([#2410](https://github.com/WordPress/wordpress-playground/pull/2410))
- [Build] Preserve optionalDependencies in built package.json. ([#2410](https://github.com/WordPress/wordpress-playground/pull/2410))

###
###

- Comlink] Throw the original error in the error handler. ([#2407](https://github.com/WordPress/wordpress-playground/pull/2407))
- Comlink] Throw the original error in the error handler. ([#2407](https://github.com/WordPress/wordpress-playground/pull/2407))

### Contributors

The following contributors merged PRs in this release:

@adamziel


## [v2.0.1] (2025-07-23)

### Blueprints
Expand Down
8 changes: 8 additions & 0 deletions packages/php-wasm/compile/php-wasm-sapi-override/config.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dnl config.m4 for extension wasm_sapi_override

PHP_ARG_ENABLE(wasm_sapi_override, whether to enable wasm_sapi_override support,
[ --enable-wasm_sapi_override Enable wasm_sapi_override support])

if test "$PHP_wasm_sapi_override" != "no"; then
PHP_NEW_EXTENSION(wasm_sapi_override, wasm_sapi_override.c, $ext_shared)
fi
5 changes: 5 additions & 0 deletions packages/php-wasm/compile/php-wasm-sapi-override/config.w32
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ARG_ENABLE("wasm_sapi_override", "Enable wasm_sapi_override support", "no");

if (PHP_wasm_sapi_override == "yes") {
EXTENSION("wasm_sapi_override", "wasm_sapi_override.c");
}
145 changes: 145 additions & 0 deletions packages/php-wasm/compile/php-wasm-sapi-override/wasm_sapi_override.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/**
* Allows changing the SAPI name at runtime.
*
* Affects:
* - php_sapi_name()
* - PHP_SAPI constant
*
* Usage:
* ```php
* set_sapi_name('wasm');
* ```
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "php.h"
#include "SAPI.h"
#include "zend_constants.h"
#include "ext/standard/info.h"
#include "wasm_sapi_override.h"
#include "ext/standard/php_string.h"
#include "zend_smart_string.h"

static char *set_sapi_name_original_name = NULL;
static char *set_sapi_name_prev_allocated = NULL;

/* {{{ proto bool set_sapi_name(string $new_name) */
PHP_FUNCTION(set_sapi_name)
{
char *new_name;
size_t new_len;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(new_name, new_len)
ZEND_PARSE_PARAMETERS_END();

/* --- overwrite sapi_module.name ------------------------------------- */
if (!set_sapi_name_original_name) {
set_sapi_name_original_name = sapi_module.name; /* remember for restore */
}

char *buf = pemalloc(new_len + 1, 1); /* persistent */
memcpy(buf, new_name, new_len);
buf[new_len] = '\0';

if (set_sapi_name_prev_allocated) {
pefree(set_sapi_name_prev_allocated, 1);
}
sapi_module.name = buf;
set_sapi_name_prev_allocated = buf;

/* --- update PHP_SAPI constant --------------------------------------- */
zend_string *const_name = zend_string_init("PHP_SAPI", sizeof("PHP_SAPI") - 1, 0);
zend_constant *c = zend_hash_find_ptr(EG(zend_constants), const_name);

zend_string *new_zstr = zend_string_init(new_name, new_len, 1); /* persistent */

if (c) {
if (Z_TYPE(c->value) == IS_STRING) {
zend_string *old = Z_STR(c->value);
/* Only release if it's not interned (interned strings live for entire process) */
if (!ZSTR_IS_INTERNED(old)) {
#if (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 2)
zend_string_release(old);
#else
zend_string_release_ex(old, 1);
#endif
}
}
ZVAL_STR(&c->value, new_zstr);
} else {
zval zv;
ZVAL_STR(&zv, new_zstr);
zend_register_constant(&(zend_constant){
.name = const_name,
.value = zv,
});
}
#if (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION == 2)
zend_string_release(const_name);
#else
zend_string_release_ex(const_name, 0);
#endif

RETURN_TRUE;
}
/* }}} */

/* arginfo */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_sapi_name, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, new_name, IS_STRING, 0)
ZEND_END_ARG_INFO()

/* function list */
static const zend_function_entry wasm_sapi_override_functions[] = {
PHP_FE(set_sapi_name, arginfo_set_sapi_name)
PHP_FE_END
};

/* MINIT / MSHUTDOWN */
static PHP_MINIT_FUNCTION(wasm_sapi_override) { return SUCCESS; }

static PHP_MSHUTDOWN_FUNCTION(wasm_sapi_override)
{
if (set_sapi_name_prev_allocated) {
pefree(set_sapi_name_prev_allocated, 1);
set_sapi_name_prev_allocated = NULL;
}
if (set_sapi_name_original_name) {
sapi_module.name = set_sapi_name_original_name;
}
return SUCCESS;
}

/* info */
static PHP_MINFO_FUNCTION(wasm_sapi_override)
{
php_info_print_table_start();
php_info_print_table_row(2, "set_sapi_name support", "enabled");
php_info_print_table_row(2, "version", PHP_WASM_SAPI_OVERRIDE_MODULE_VERSION);
php_info_print_table_row(2, "current SAPI", sapi_module.name);
php_info_print_table_end();
}

/* module entry */
zend_module_entry wasm_sapi_override_module_entry = {
STANDARD_MODULE_HEADER,
"wasm_sapi_override", /* Extension name */
wasm_sapi_override_functions, /* Function entries */
PHP_MINIT(wasm_sapi_override), /* PHP_MINIT - Module initialization */
PHP_MSHUTDOWN(wasm_sapi_override), /* PHP_MSHUTDOWN - Module shutdown */
NULL, /* PHP_RINIT - Request initialization */
NULL, /* PHP_RSHUTDOWN - Request shutdown */
PHP_MINFO(wasm_sapi_override), /* PHP_MINFO - Module info */
PHP_WASM_SAPI_OVERRIDE_MODULE_VERSION, /* Version */
STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_WASM_SAPI_OVERRIDE
# ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
# endif
ZEND_GET_MODULE(wasm_sapi_override)
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* wasm_memory_storage extension for PHP */

#ifndef PHP_WASM_SAPI_OVERRIDE_H
# define PHP_WASM_SAPI_OVERRIDE_H

extern zend_module_entry wasm_sapi_override_module_entry;
# define phpext_wasm_sapi_override_ptr &wasm_sapi_override_module_entry

# define PHP_WASM_SAPI_OVERRIDE_MODULE_VERSION "0.0.1"

#endif /* PHP_WASM_SAPI_OVERRIDE_H */
Loading
Loading