Skip to content

Commit 4a119f9

Browse files
committed
Improved FastCGI SAPI to support external pipe and socket servers on win32
1 parent 1c36d38 commit 4a119f9

File tree

4 files changed

+199
-77
lines changed

4 files changed

+199
-77
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PHP NEWS
99
- Upgraded SQLite 3 to version 3.3.13 (Ilia)
1010
- Upgraded PCRE to version 7.0 (Nuno)
1111
- Updated timezone database to version 2007.3. (Derick)
12+
- Improved FastCGI SAPI to support external pipe and socket servers on win32.
13+
(Dmitry)
1214
- Improved Zend Memory Manager
1315
. guarantee of reasonable time for worst cases of best-fit free block
1416
searching algorithm. (Dmitry)
@@ -58,6 +60,7 @@ PHP NEWS
5860
- Fixed bug #40770 (Apache child exits when PHP memory limit reached). (Dmitry)
5961
- Fixed bug #40764 (line thickness not respected for horizontal and vertical
6062
lines). (Pierre)
63+
- Fixed bug #40758 (Test fcgi_is_fastcgi() is wrong on windows). (Dmitry)
6164
- Fixed bug #40754 (added substr() & substr_replace() overflow checks). (Ilia)
6265
- Fixed bug #40752 (parse_ini_file() segfaults when a scalar setting is
6366
redeclared as an array). (Tony)

sapi/cgi/cgi_main.c

+3-44
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ static zend_module_entry cgi_module_entry;
123123

124124
static const opt_struct OPTIONS[] = {
125125
{'a', 0, "interactive"},
126-
#ifndef PHP_WIN32
127126
{'b', 1, "bindpath"},
128-
#endif
129127
{'C', 0, "no-chdir"},
130128
{'c', 1, "php-ini"},
131129
{'d', 1, "define"},
@@ -630,7 +628,7 @@ static void php_cgi_usage(char *argv0)
630628
php_printf("Usage: %s [-q] [-h] [-s] [-v] [-i] [-f <file>]\n"
631629
" %s <file> [args...]\n"
632630
" -a Run interactively\n"
633-
#if PHP_FASTCGI && !defined(PHP_WIN32)
631+
#if PHP_FASTCGI
634632
" -b <address:port>|<port> Bind Path for external FASTCGI Server mode\n"
635633
#endif
636634
" -C Do not chdir to the script's directory\n"
@@ -997,21 +995,6 @@ void fastcgi_cleanup(int signal)
997995
}
998996
#endif
999997

1000-
#if PHP_FASTCGI
1001-
#ifndef PHP_WIN32
1002-
static int is_port_number(const char *bindpath)
1003-
{
1004-
while (*bindpath) {
1005-
if (*bindpath < '0' || *bindpath > '9') {
1006-
return 0;
1007-
}
1008-
bindpath++;
1009-
}
1010-
return 1;
1011-
}
1012-
#endif
1013-
#endif
1014-
1015998
PHP_INI_BEGIN()
1016999
STD_PHP_INI_ENTRY("cgi.rfc2616_headers", "0", PHP_INI_ALL, OnUpdateBool, rfc2616_headers, php_cgi_globals_struct, php_cgi_globals)
10171000
STD_PHP_INI_ENTRY("cgi.nph", "0", PHP_INI_ALL, OnUpdateBool, nph, php_cgi_globals_struct, php_cgi_globals)
@@ -1133,9 +1116,7 @@ int main(int argc, char *argv[])
11331116
int max_requests = 500;
11341117
int requests = 0;
11351118
int fastcgi = fcgi_is_fastcgi();
1136-
#ifndef PHP_WIN32
11371119
char *bindpath = NULL;
1138-
#endif
11391120
int fcgi_fd = 0;
11401121
fcgi_request request;
11411122
#ifndef PHP_WIN32
@@ -1233,8 +1214,6 @@ int main(int argc, char *argv[])
12331214
}
12341215
break;
12351216
}
1236-
#if PHP_FASTCGI
1237-
#ifndef PHP_WIN32
12381217
/* if we're started on command line, check to see if
12391218
we are being started as an 'external' fastcgi
12401219
server by accepting a bindpath parameter. */
@@ -1243,8 +1222,6 @@ int main(int argc, char *argv[])
12431222
bindpath = strdup(php_optarg);
12441223
}
12451224
break;
1246-
#endif
1247-
#endif
12481225
}
12491226

12501227
}
@@ -1311,26 +1288,10 @@ consult the installation file that came with this distribution, or visit \n\
13111288
#endif /* FORCE_CGI_REDIRECT */
13121289

13131290
#if PHP_FASTCGI
1314-
#ifndef PHP_WIN32
13151291
/* for windows, socket listening is broken in the fastcgi library itself
13161292
so dissabling this feature on windows till time is available to fix it */
13171293
if (bindpath) {
1318-
/* Pass on the arg to the FastCGI library, with one exception.
1319-
* If just a port is specified, then we prepend a ':' onto the
1320-
* path (it's what the fastcgi library expects)
1321-
*/
1322-
if (strchr(bindpath, ':') == NULL && is_port_number(bindpath)) {
1323-
char *tmp;
1324-
1325-
tmp = malloc(strlen(bindpath) + 2);
1326-
tmp[0] = ':';
1327-
memcpy(tmp + 1, bindpath, strlen(bindpath) + 1);
1328-
1329-
fcgi_fd = fcgi_listen(tmp, 128);
1330-
free(tmp);
1331-
} else {
1332-
fcgi_fd = fcgi_listen(bindpath, 128);
1333-
}
1294+
fcgi_fd = fcgi_listen(bindpath, 128);
13341295
if (fcgi_fd < 0) {
13351296
fprintf(stderr, "Couldn't create FastCGI listen socket on port %s\n", bindpath);
13361297
#ifdef ZTS
@@ -1340,7 +1301,7 @@ consult the installation file that came with this distribution, or visit \n\
13401301
}
13411302
fastcgi = fcgi_is_fastcgi();
13421303
}
1343-
#endif
1304+
13441305
if (fastcgi) {
13451306
/* How many times to run PHP scripts before dying */
13461307
if (getenv("PHP_FCGI_MAX_REQUESTS")) {
@@ -1828,11 +1789,9 @@ consult the installation file that came with this distribution, or visit \n\
18281789
requests++;
18291790
if (max_requests && (requests == max_requests)) {
18301791
fcgi_finish_request(&request);
1831-
#ifndef PHP_WIN32
18321792
if (bindpath) {
18331793
free(bindpath);
18341794
}
1835-
#endif
18361795
break;
18371796
}
18381797
/* end of fastcgi loop */

0 commit comments

Comments
 (0)