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

perf: cgi-mode 1700% improvement #933

Merged
merged 5 commits into from
Jul 26, 2024
Merged
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
43 changes: 18 additions & 25 deletions frankenphp.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ typedef struct frankenphp_server_context {
bool finished;
} frankenphp_server_context;

__thread frankenphp_server_context *local_ctx = NULL;
dunglas marked this conversation as resolved.
Show resolved Hide resolved

static void frankenphp_free_request_context() {
frankenphp_server_context *ctx = SG(server_context);

Expand Down Expand Up @@ -430,12 +432,7 @@ static void frankenphp_request_shutdown() {
php_request_shutdown((void *)0);
frankenphp_free_request_context();

free(ctx);
SG(server_context) = ctx = NULL;

#if defined(ZTS)
ts_free_thread();
#endif
memset(local_ctx, 0, sizeof(frankenphp_server_context));
withinboredom marked this conversation as resolved.
Show resolved Hide resolved
}

int frankenphp_update_server_context(
Expand All @@ -447,20 +444,7 @@ int frankenphp_update_server_context(
frankenphp_server_context *ctx;

if (create) {
#ifdef ZTS
/* initial resource fetch */
(void)ts_resource(0);
#ifdef PHP_WIN32
ZEND_TSRMLS_CACHE_UPDATE();
#endif
#endif

/* todo: use a pool */
ctx =
(frankenphp_server_context *)malloc(sizeof(frankenphp_server_context));
if (ctx == NULL) {
return FAILURE;
}
ctx = local_ctx;

ctx->worker_ready = false;
ctx->cookie_data = NULL;
Expand Down Expand Up @@ -746,9 +730,23 @@ static void *php_thread(void *arg) {
snprintf(thread_name, 16, "php-%" PRIxPTR, (uintptr_t)arg);
set_thread_name(thread_name);

#ifdef ZTS
/* initial resource fetch */
(void)ts_resource(0);
#ifdef PHP_WIN32
ZEND_TSRMLS_CACHE_UPDATE();
#endif
#endif

local_ctx = malloc(sizeof(frankenphp_server_context));

while (go_handle_request()) {
}

#ifdef ZTS
ts_free_thread();
#endif

return NULL;
}

Expand Down Expand Up @@ -861,11 +859,6 @@ int frankenphp_request_startup() {
return SUCCESS;
}

frankenphp_server_context *ctx = SG(server_context);
SG(server_context) = NULL;
free(ctx);
ctx = NULL;

php_request_shutdown((void *)0);

return FAILURE;
Expand Down
Loading