]> git.pld-linux.org Git - packages/php.git/blob - php-fcgi-graceful.patch
- handle graceful restart on SIGTERM, so scripts need not to be modified
[packages/php.git] / php-fcgi-graceful.patch
1 --- php5.3-200711071330/sapi/cgi/cgi_main.c     2007-11-01 13:32:38.000000000 +0200
2 +++ php5.3-200711071330-graceful2/sapi/cgi/cgi_main.c   2007-11-07 22:12:10.025949153 +0200
3 @@ -101,6 +101,9 @@
4   */
5  static int parent = 1;
6  
7 +/* Socket we are listening on incoming connections */
8 +static int fcgi_fd = 0;
9 +
10  /**
11   * Process group
12   */
13 @@ -1221,6 +1224,21 @@
14         exit(0);
15  }
16  
17 +/**
18 + * Graceful shutdown. Close listening sockets.
19 + */
20 +void fastcgi_graceful_shutdown(int signal)
21 +{
22 +#ifdef DEBUG_FASTCGI
23 +       fprintf(stderr, "FastCGI graceful shutdown, pid %d\n", getpid());
24 +#endif
25 +
26 +       /* Close the listening socket so new processes can reuse the same port */
27 +       closesocket(fcgi_fd);
28 +       fcgi_fd = 0;
29 +}
30 +
31 +
32  PHP_INI_BEGIN()
33         STD_PHP_INI_ENTRY("cgi.rfc2616_headers",     "0",  PHP_INI_ALL,    OnUpdateBool,   rfc2616_headers, php_cgi_globals_struct, php_cgi_globals)
34         STD_PHP_INI_ENTRY("cgi.nph",                 "0",  PHP_INI_ALL,    OnUpdateBool,   nph, php_cgi_globals_struct, php_cgi_globals)
35 @@ -1328,7 +1346,6 @@
36         int requests = 0;
37         int fastcgi = fcgi_is_fastcgi();
38         char *bindpath = NULL;
39 -       int fcgi_fd = 0;
40         fcgi_request request;
41         int repeats = 1;
42         int benchmark = 0;
43 @@ -1579,9 +1596,13 @@
44                                         parent = 0;
45  
46                                         /* don't catch our signals */
47 -                                       sigaction(SIGTERM, &old_term, 0);
48 -                                       sigaction(SIGQUIT, &old_quit, 0);
49 -                                       sigaction(SIGINT,  &old_int,  0);
50 +                                       sigaction(SIGQUIT, &act, &old_quit);
51 +                                       sigaction(SIGINT, &act, &old_int);
52 +
53 +                                       /* call graceful shutdown handler for SIGTERM */
54 +                                       act.sa_flags = 0;
55 +                                       act.sa_handler = fastcgi_graceful_shutdown;
56 +                                       sigaction(SIGTERM, &act, &old_term);
57                                         break;
58                                 case -1:
59                                         perror("php (pre-forking)");
This page took 0.036124 seconds and 4 git commands to generate.