Skip to content
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

Fix shutdown errors #1104

Merged
merged 9 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions packages/php-wasm/compile/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ RUN echo -n ' -s ASYNCIFY=1 -s ASYNCIFY_IGNORE_INDIRECT=1 ' >> /root/.emcc-php-w
"get_http_body",\
"wasm_php_exec",\
"wasm_sapi_handle_request",\
"wasm_sapi_request_shutdown",\
"_call_user_function_ex",\
"_call_user_function_impl",\
"_mysqlnd_run_command",\
Expand Down Expand Up @@ -786,6 +787,7 @@ RUN set -euxo pipefail; \
"_wasm_add_ENV_entry", \n\
"_wasm_read", \n\
"_wasm_sapi_handle_request", \n\
"_wasm_sapi_request_shutdown", \n\
"_wasm_set_content_length", \n\
"_wasm_set_content_type", \n\
"_wasm_set_cookies", \n\
Expand Down
13 changes: 5 additions & 8 deletions packages/php-wasm/compile/php/php_wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ PHP_FUNCTION(post_message_to_js)

char *response;
size_t response_len = js_module_onMessage(data, &response);
if (response != NULL)
if (response_len != -1)
{
zend_string *return_string = zend_string_init(response, response_len, 0);
free(response);
Expand Down Expand Up @@ -1071,6 +1071,8 @@ static void wasm_sapi_register_server_variables(zval *track_vars_array TSRMLS_DC
value = SG(request_info).request_uri;
if (value != NULL)
{
php_register_variable("SCRIPT_NAME", value, track_vars_array TSRMLS_CC);
php_register_variable("SCRIPT_FILENAME", value, track_vars_array TSRMLS_CC);
php_register_variable("REQUEST_URI", value, track_vars_array TSRMLS_CC);
}

Expand All @@ -1079,7 +1081,7 @@ static void wasm_sapi_register_server_variables(zval *track_vars_array TSRMLS_DC
{
// Confirm path translated starts with the document root
/**
* PHP_SELF is the script path relative to the document root.
* PHP_SELF is the script path relative to the document rooth.
*
* For example:
*
Expand All @@ -1095,11 +1097,7 @@ static void wasm_sapi_register_server_variables(zval *track_vars_array TSRMLS_DC
if (strncmp(wasm_server_context->document_root, wasm_server_context->path_translated, strlen(wasm_server_context->document_root)) == 0)
{
// Substring of path translated starting after document root
char *script_name = wasm_server_context->path_translated + strlen(wasm_server_context->document_root);
char *script_filename = wasm_server_context->path_translated;
char *php_self = wasm_server_context->path_translated + strlen(wasm_server_context->document_root);
php_register_variable("SCRIPT_NAME", estrdup(script_name), track_vars_array TSRMLS_CC);
php_register_variable("SCRIPT_FILENAME", estrdup(script_filename), track_vars_array TSRMLS_CC);
php_register_variable("PHP_SELF", estrdup(php_self), track_vars_array TSRMLS_CC);
php_self_set = 1;
}
Expand All @@ -1108,8 +1106,6 @@ static void wasm_sapi_register_server_variables(zval *track_vars_array TSRMLS_DC
if (php_self_set == 0 && value != NULL)
{
// Default to REQUEST_URI
php_register_variable("SCRIPT_NAME", value, track_vars_array TSRMLS_CC);
php_register_variable("SCRIPT_FILENAME", value, track_vars_array TSRMLS_CC);
php_register_variable("PHP_SELF", value, track_vars_array TSRMLS_CC);
}

Expand Down Expand Up @@ -1326,6 +1322,7 @@ int EMSCRIPTEN_KEEPALIVE wasm_sapi_handle_request()
run_php(wasm_server_context->php_code);
}
result = EG(exit_status);

wasm_request_done:
wasm_sapi_request_shutdown();
return result;
Expand Down
Loading
Loading