]> git.pld-linux.org Git - packages/php.git/blame - php-fcgi-graceful.patch
Release 41 (by relup.sh)
[packages/php.git] / php-fcgi-graceful.patch
CommitLineData
e7cc86fc
ER
1Related links:
2
3http://bugs.php.net/bug.php?id=41593
4http://bugs.php.net/bug.php?id=36158
fd3f03f7 5http://bugs.php.net/bug.php?id=43224
e7cc86fc
ER
6http://php-fpm.anight.org/
7
42e16ac8
ER
8test script too:
9<?php
10echo php_sapi_name(), ' running ', PHP_VERSION, "<br>\n";
11$i = 0;
12while ($i < 35) {
13 echo (++$i), "<br>\n";
14 flush();
15 sleep(1);
16}
17echo "end!<br>\n";
18?>
19
f9fed404
AM
20diff -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
3e6c63d7 24 */
f9fed404 25 static int children = 0;
3e6c63d7 26
2a5af13b
ER
27+#if PHP_FASTCGI
28+/* Socket we are listening on incoming FastCGI connections */
16da4523 29+static int fcgi_fd = 0;
2a5af13b 30+#endif
3e6c63d7
ER
31+
32 /**
f9fed404 33 * Set to non-zero if we are the parent process
3e6c63d7 34 */
f9fed404 35@@ -1225,6 +1230,22 @@ void fastcgi_cleanup(int signal)
3e6c63d7 36 }
2a5af13b 37 #endif
3e6c63d7 38
2a5af13b 39+#if PHP_FASTCGI
3e6c63d7
ER
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+
7a7f999c 49+ /* Close the listening socket so new processes can reuse the same port */
3e6c63d7 50+ closesocket(fcgi_fd);
16da4523 51+ fcgi_fd = 0;
3e6c63d7 52+}
2a5af13b 53+#endif
3e6c63d7
ER
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)
f9fed404 58@@ -1343,7 +1364,6 @@ int main(int argc, char *argv[])
3e6c63d7
ER
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;
f9fed404 66@@ -1632,9 +1652,17 @@ consult the installation file that came
7a7f999c
ER
67 parent = 0;
68
3e6c63d7 69 /* don't catch our signals */
7a7f999c 70- sigaction(SIGTERM, &old_term, 0);
2a5af13b
ER
71 sigaction(SIGQUIT, &old_quit, 0);
72 sigaction(SIGINT, &old_int, 0);
73+#if PHP_FASTCGI
7a7f999c
ER
74+
75+ /* call graceful shutdown handler for SIGTERM */
3e6c63d7
ER
76+ act.sa_flags = 0;
77+ act.sa_handler = fastcgi_graceful_shutdown;
7a7f999c 78+ sigaction(SIGTERM, &act, &old_term);
2a5af13b
ER
79+#else
80+ sigaction(SIGTERM, &old_term, 0);
81+#endif
3e6c63d7
ER
82 break;
83 case -1:
84 perror("php (pre-forking)");
This page took 0.292291 seconds and 4 git commands to generate.