]> git.pld-linux.org Git - packages/php.git/blob - php-fcgi-graceful.patch
Rediff patches.
[packages/php.git] / php-fcgi-graceful.patch
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 diff -urNp -x '*.orig' php-5.2.17.org/sapi/cgi/cgi_main.c php-5.2.17/sapi/cgi/cgi_main.c
21 --- php-5.2.17.org/sapi/cgi/cgi_main.c  2021-10-23 19:05:04.013125101 +0200
22 +++ php-5.2.17/sapi/cgi/cgi_main.c      2021-10-23 19:05:06.359791768 +0200
23 @@ -100,6 +100,11 @@ static void (*php_php_import_environment
24   */
25  static int children = 0;
26  
27 +#if PHP_FASTCGI
28 +/* Socket we are listening on incoming FastCGI connections */
29 +static int fcgi_fd = 0;
30 +#endif
31 +
32  /**
33   * Set to non-zero if we are the parent process
34   */
35 @@ -1225,6 +1230,22 @@ void fastcgi_cleanup(int signal)
36  }
37  #endif
38  
39 +#if PHP_FASTCGI
40 +/**
41 + * Graceful shutdown. Close listening sockets.
42 + */
43 +void fastcgi_graceful_shutdown(int signal)
44 +{
45 +#ifdef DEBUG_FASTCGI
46 +       fprintf(stderr, "FastCGI graceful shutdown, pid %d\n", getpid());
47 +#endif
48 +
49 +       /* Close the listening socket so new processes can reuse the same port */
50 +       closesocket(fcgi_fd);
51 +       fcgi_fd = 0;
52 +}
53 +#endif
54 +
55  PHP_INI_BEGIN()
56         STD_PHP_INI_ENTRY("cgi.rfc2616_headers",     "0",  PHP_INI_ALL,    OnUpdateBool,   rfc2616_headers, php_cgi_globals_struct, php_cgi_globals)
57         STD_PHP_INI_ENTRY("cgi.nph",                 "0",  PHP_INI_ALL,    OnUpdateBool,   nph, php_cgi_globals_struct, php_cgi_globals)
58 @@ -1343,7 +1364,6 @@ int main(int argc, char *argv[])
59         int requests = 0;
60         int fastcgi = fcgi_is_fastcgi();
61         char *bindpath = NULL;
62 -       int fcgi_fd = 0;
63         fcgi_request request;
64         int repeats = 1;
65         int benchmark = 0;
66 @@ -1632,9 +1652,17 @@ consult the installation file that came
67                                         parent = 0;
68  
69                                         /* don't catch our signals */
70 -                                       sigaction(SIGTERM, &old_term, 0);
71                                         sigaction(SIGQUIT, &old_quit, 0);
72                                         sigaction(SIGINT,  &old_int,  0);
73 +#if PHP_FASTCGI
74 +
75 +                                       /* call graceful shutdown handler for SIGTERM */
76 +                                       act.sa_flags = 0;
77 +                                       act.sa_handler = fastcgi_graceful_shutdown;
78 +                                       sigaction(SIGTERM, &act, &old_term);
79 +#else
80 +                                       sigaction(SIGTERM, &old_term, 0);
81 +#endif
82                                         break;
83                                 case -1:
84                                         perror("php (pre-forking)");
This page took 0.03409 seconds and 3 git commands to generate.