From 082ac0d8b1bab1b49ca4258ce3dc866ebb2aeead Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 10 Apr 2024 22:10:31 +0100 Subject: [PATCH] sapi/fcgi: update listen queue size handling. the default backlog does not necessarily need to be higher than 128, however for systems like haiku it s mor benefitial to be actually lower. --- sapi/cgi/cgi_main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index 9d7e66ce2b5b..d5c488821113 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -1918,10 +1918,17 @@ consult the installation file that came with this distribution, or visit \n\ #endif if (bindpath) { - int backlog = 128; + int backlog = MIN(SOMAXCONN, 128); if (getenv("PHP_FCGI_BACKLOG")) { backlog = atoi(getenv("PHP_FCGI_BACKLOG")); } + if (backlog < -1 || backlog > SOMAXCONN) { + fprintf(stderr, "Invalid backlog %d, needs to be between -1 and %d\n", backlog, SOMAXCONN); +#ifdef ZTS + tsrm_shutdown(); +#endif + return FAILURE; + } fcgi_fd = fcgi_listen(bindpath, backlog); if (fcgi_fd < 0) { fprintf(stderr, "Couldn't create FastCGI listen socket on port %s\n", bindpath);