]>
Commit | Line | Data |
---|---|---|
1 | Related links: | |
2 | ||
3 | http://bugs.php.net/bug.php?id=41593 | |
4 | http://bugs.php.net/bug.php?id=36158 | |
5 | http://bugs.php.net/bug.php?id=43224 | |
6 | http://php-fpm.anight.org/ | |
7 | ||
8 | test script too: | |
9 | <?php | |
10 | echo php_sapi_name(), ' running ', PHP_VERSION, "<br>\n"; | |
11 | $i = 0; | |
12 | while ($i < 35) { | |
13 | echo (++$i), "<br>\n"; | |
14 | flush(); | |
15 | sleep(1); | |
16 | } | |
17 | echo "end!<br>\n"; | |
18 | ?> | |
19 | ||
20 | --- php-5.2.5RC2/sapi/cgi/cgi_main.c 2007-11-01 17:23:14.000000000 +0200 | |
21 | +++ php-5.2.5RC2-graceful/sapi/cgi/cgi_main.c 2007-11-08 00:46:38.999355875 +0200 | |
22 | @@ -103,6 +103,11 @@ | |
23 | */ | |
24 | static int parent = 1; | |
25 | ||
26 | +#if PHP_FASTCGI | |
27 | +/* Socket we are listening on incoming FastCGI connections */ | |
28 | +static int fcgi_fd = 0; | |
29 | +#endif | |
30 | + | |
31 | /** | |
32 | * Process group | |
33 | */ | |
34 | @@ -1157,6 +1162,22 @@ | |
35 | } | |
36 | #endif | |
37 | ||
38 | +#if PHP_FASTCGI | |
39 | +/** | |
40 | + * Graceful shutdown. Close listening sockets. | |
41 | + */ | |
42 | +void fastcgi_graceful_shutdown(int signal) | |
43 | +{ | |
44 | +#ifdef DEBUG_FASTCGI | |
45 | + fprintf(stderr, "FastCGI graceful shutdown, pid %d\n", getpid()); | |
46 | +#endif | |
47 | + | |
48 | + /* Close the listening socket so new processes can reuse the same port */ | |
49 | + closesocket(fcgi_fd); | |
50 | + fcgi_fd = 0; | |
51 | +} | |
52 | +#endif | |
53 | + | |
54 | PHP_INI_BEGIN() | |
55 | STD_PHP_INI_ENTRY("cgi.rfc2616_headers", "0", PHP_INI_ALL, OnUpdateBool, rfc2616_headers, php_cgi_globals_struct, php_cgi_globals) | |
56 | STD_PHP_INI_ENTRY("cgi.nph", "0", PHP_INI_ALL, OnUpdateBool, nph, php_cgi_globals_struct, php_cgi_globals) | |
57 | @@ -1275,7 +1296,6 @@ | |
58 | int requests = 0; | |
59 | int fastcgi = fcgi_is_fastcgi(); | |
60 | char *bindpath = NULL; | |
61 | - int fcgi_fd = 0; | |
62 | fcgi_request request; | |
63 | int repeats = 1; | |
64 | int benchmark = 0; | |
65 | @@ -1538,9 +1558,17 @@ | |
66 | parent = 0; | |
67 | ||
68 | /* don't catch our signals */ | |
69 | - sigaction(SIGTERM, &old_term, 0); | |
70 | sigaction(SIGQUIT, &old_quit, 0); | |
71 | sigaction(SIGINT, &old_int, 0); | |
72 | +#if PHP_FASTCGI | |
73 | + | |
74 | + /* call graceful shutdown handler for SIGTERM */ | |
75 | + act.sa_flags = 0; | |
76 | + act.sa_handler = fastcgi_graceful_shutdown; | |
77 | + sigaction(SIGTERM, &act, &old_term); | |
78 | +#else | |
79 | + sigaction(SIGTERM, &old_term, 0); | |
80 | +#endif | |
81 | break; | |
82 | case -1: | |
83 | perror("php (pre-forking)"); |