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