]> git.pld-linux.org Git - packages/php.git/blob - php-fcgi-graceful.patch
- attempt to implement graceful shutdown with SIGINT signal
[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-graceful/sapi/cgi/cgi_main.c    2007-11-07 17:40:37.884171760 +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 = -1;
9 +
10  /**
11   * Process group
12   */
13 @@ -116,6 +119,7 @@
14  static char *php_optarg = NULL;
15  static int php_optind = 1;
16  static zend_module_entry cgi_module_entry;
17 +static int accept_socket = -1;
18  
19  static const opt_struct OPTIONS[] = {
20         {'a', 0, "interactive"},
21 @@ -1211,16 +1215,38 @@
22  #endif
23  
24  #ifndef PHP_WIN32
25 -       sigaction(SIGTERM, &old_term, 0);
26 -
27         /* Kill all the processes in our process group */
28 -       kill(-pgroup, SIGTERM);
29 +       if (signal == SIGINT) {
30 +               sigaction(SIGTERM, &old_int, 0);
31 +               kill(-pgroup, SIGINT);
32 +       } else {
33 +               sigaction(SIGTERM, &old_term, 0);
34 +               kill(-pgroup, SIGTERM);
35 +       }
36  #endif
37  
38         /* We should exit at this point, but MacOSX doesn't seem to */
39         exit(0);
40  }
41  
42 +/**
43 + * Graceful shutdown. Close listening sockets.
44 + */
45 +void fastcgi_graceful_shutdown(int signal)
46 +{
47 +#ifdef DEBUG_FASTCGI
48 +       fprintf(stderr, "FastCGI graceful shutdown, pid %d\n", getpid());
49 +#endif
50 +
51 +       /* This will make FCGI shutdown itself later in the loop, however we should finish our request cleanly */
52 +       fcgi_shutdown();
53 +
54 +       /* Whoever we also close the listeing socket (which PHP itself doesn't seem to do?!) */
55 +       closesocket(fcgi_fd);
56 +       fcgi_fd = -1;
57 +}
58 +
59 +
60  PHP_INI_BEGIN()
61         STD_PHP_INI_ENTRY("cgi.rfc2616_headers",     "0",  PHP_INI_ALL,    OnUpdateBool,   rfc2616_headers, php_cgi_globals_struct, php_cgi_globals)
62         STD_PHP_INI_ENTRY("cgi.nph",                 "0",  PHP_INI_ALL,    OnUpdateBool,   nph, php_cgi_globals_struct, php_cgi_globals)
63 @@ -1328,7 +1354,6 @@
64         int requests = 0;
65         int fastcgi = fcgi_is_fastcgi();
66         char *bindpath = NULL;
67 -       int fcgi_fd = 0;
68         fcgi_request request;
69         int repeats = 1;
70         int benchmark = 0;
71 @@ -1581,7 +1606,10 @@
72                                         /* don't catch our signals */
73                                         sigaction(SIGTERM, &old_term, 0);
74                                         sigaction(SIGQUIT, &old_quit, 0);
75 -                                       sigaction(SIGINT,  &old_int,  0);
76 +                                       /* handler for SIGINT */
77 +                                       act.sa_flags = 0;
78 +                                       act.sa_handler = fastcgi_graceful_shutdown;
79 +                                       sigaction(SIGINT, &act, &old_int);
80                                         break;
81                                 case -1:
82                                         perror("php (pre-forking)");
This page took 0.029791 seconds and 4 git commands to generate.