Skip to content

FPM: fastcgi_finish_request supports force close connection param #10273

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 2 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 12 additions & 4 deletions sapi/fpm/fpm/fpm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ typedef struct _php_cgi_globals_struct {
bool discard_path;
bool fcgi_logging;
bool fcgi_logging_request_started;
bool fcgi_auto_close_conn;
char *redirect_status_env;
HashTable user_config_cache;
char *error_header;
Expand Down Expand Up @@ -1431,6 +1432,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("cgi.fix_pathinfo", "1", PHP_INI_SYSTEM, OnUpdateBool, fix_pathinfo, php_cgi_globals_struct, php_cgi_globals)
STD_PHP_INI_BOOLEAN("cgi.discard_path", "0", PHP_INI_SYSTEM, OnUpdateBool, discard_path, php_cgi_globals_struct, php_cgi_globals)
STD_PHP_INI_BOOLEAN("fastcgi.logging", "1", PHP_INI_SYSTEM, OnUpdateBool, fcgi_logging, php_cgi_globals_struct, php_cgi_globals)
STD_PHP_INI_BOOLEAN("fastcgi.auto_close_connection", "1", PHP_INI_SYSTEM, OnUpdateBool, fcgi_auto_close_conn, php_cgi_globals_struct, php_cgi_globals)
STD_PHP_INI_ENTRY("fastcgi.error_header", NULL, PHP_INI_SYSTEM, OnUpdateString, error_header, php_cgi_globals_struct, php_cgi_globals)
STD_PHP_INI_ENTRY("fpm.config", NULL, PHP_INI_SYSTEM, OnUpdateString, fpm_config, php_cgi_globals_struct, php_cgi_globals)
PHP_INI_END()
Expand All @@ -1446,6 +1448,7 @@ static void php_cgi_globals_ctor(php_cgi_globals_struct *php_cgi_globals)
php_cgi_globals->discard_path = 0;
php_cgi_globals->fcgi_logging = 1;
php_cgi_globals->fcgi_logging_request_started = false;
php_cgi_globals->fcgi_auto_close_conn = true;
zend_hash_init(&php_cgi_globals->user_config_cache, 0, NULL, user_config_cache_entry_dtor, 1);
php_cgi_globals->error_header = NULL;
php_cgi_globals->fpm_config = NULL;
Expand Down Expand Up @@ -1488,18 +1491,23 @@ static PHP_MINFO_FUNCTION(cgi)

PHP_FUNCTION(fastcgi_finish_request) /* {{{ */
{
bool close_conn = CGIG(fcgi_auto_close_conn);
fcgi_request *request = (fcgi_request*) SG(server_context);

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_BOOL(close_conn)
ZEND_PARSE_PARAMETERS_END();

if (!fcgi_is_closed(request)) {
php_output_end_all();
php_header();

if (close_conn) {
fcgi_request_set_keep(request, 0);
}
fcgi_end(request);
fcgi_close(request, 0, 0);
fcgi_close(request, 0, close_conn);
RETURN_TRUE;
}

Expand Down
2 changes: 1 addition & 1 deletion sapi/fpm/fpm/fpm_main.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/** @generate-class-entries */

function fastcgi_finish_request(): bool {}
function fastcgi_finish_request(bool $close_conn = true): bool {}

function apache_request_headers(): array {}

Expand Down
3 changes: 2 additions & 1 deletion sapi/fpm/fpm/fpm_main_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading