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