Skip to content

Commit b2f4e68

Browse files
author
Jerome Loyet
committed
Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3: - Fixed bug #63085 (Systemd integration and daemonize) - Fixed bug #62954 (startup problems fpm / php-fpm) - Fixed bug #62886 (PHP-FPM may segfault/hang on startup) Conflicts: sapi/fpm/config.m4
2 parents b5eb145 + 851a04b commit b2f4e68

File tree

8 files changed

+51
-664
lines changed

8 files changed

+51
-664
lines changed

sapi/fpm/config.m4

Lines changed: 0 additions & 653 deletions
Large diffs are not rendered by default.

sapi/fpm/fpm/fpm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct fpm_globals_s fpm_globals = {
4242
.send_config_pipe = {0, 0},
4343
};
4444

45-
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root) /* {{{ */
45+
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon) /* {{{ */
4646
{
4747
fpm_globals.argc = argc;
4848
fpm_globals.argv = argv;
@@ -55,7 +55,7 @@ int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int t
5555

5656
if (0 > fpm_php_init_main() ||
5757
0 > fpm_stdio_init_main() ||
58-
0 > fpm_conf_init_main(test_conf) ||
58+
0 > fpm_conf_init_main(test_conf, force_daemon) ||
5959
0 > fpm_unix_init_main() ||
6060
0 > fpm_scoreboard_init_main() ||
6161
0 > fpm_pctl_init_main() ||

sapi/fpm/fpm/fpm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838

3939
int fpm_run(int *max_requests);
40-
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root);
40+
int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int test_conf, int run_as_root, int force_daemon);
4141

4242
struct fpm_globals_s {
4343
pid_t parent_pid;

sapi/fpm/fpm/fpm_conf.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,14 +1115,19 @@ int fpm_conf_write_pid() /* {{{ */
11151115
}
11161116
/* }}} */
11171117

1118-
static int fpm_conf_post_process(TSRMLS_D) /* {{{ */
1118+
static int fpm_conf_post_process(int force_daemon TSRMLS_DC) /* {{{ */
11191119
{
11201120
struct fpm_worker_pool_s *wp;
11211121

11221122
if (fpm_global_config.pid_file) {
11231123
fpm_evaluate_full_path(&fpm_global_config.pid_file, NULL, PHP_LOCALSTATEDIR, 0);
11241124
}
11251125

1126+
if (force_daemon >= 0) {
1127+
/* forced from command line options */
1128+
fpm_global_config.daemonize = force_daemon;
1129+
}
1130+
11261131
fpm_globals.log_level = fpm_global_config.log_level;
11271132

11281133
if (fpm_global_config.process_max < 0) {
@@ -1584,7 +1589,7 @@ static void fpm_conf_dump() /* {{{ */
15841589
}
15851590
/* }}} */
15861591

1587-
int fpm_conf_init_main(int test_conf) /* {{{ */
1592+
int fpm_conf_init_main(int test_conf, int force_daemon) /* {{{ */
15881593
{
15891594
int ret;
15901595
TSRMLS_FETCH();
@@ -1630,7 +1635,7 @@ int fpm_conf_init_main(int test_conf) /* {{{ */
16301635
return -1;
16311636
}
16321637

1633-
if (0 > fpm_conf_post_process(TSRMLS_C)) {
1638+
if (0 > fpm_conf_post_process(force_daemon TSRMLS_CC)) {
16341639
zlog(ZLOG_ERROR, "failed to post process the configuration");
16351640
return -1;
16361641
}

sapi/fpm/fpm/fpm_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ enum {
9797
PM_STYLE_ONDEMAND = 3
9898
};
9999

100-
int fpm_conf_init_main(int test_conf);
100+
int fpm_conf_init_main(int test_conf, int force_daemon);
101101
int fpm_worker_pool_config_free(struct fpm_worker_pool_config_s *wpc);
102102
int fpm_conf_write_pid();
103103
int fpm_conf_unlink_pid();

sapi/fpm/fpm/fpm_main.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ static const opt_struct OPTIONS[] = {
155155
{'p', 1, "prefix"},
156156
{'g', 1, "pid"},
157157
{'R', 0, "allow-to-run-as-root"},
158+
{'D', 0, "daemonize"},
159+
{'F', 0, "nodaemonize"},
158160
{'-', 0, NULL} /* end of args */
159161
};
160162

@@ -912,7 +914,7 @@ static void php_cgi_usage(char *argv0)
912914
prog = "php";
913915
}
914916

915-
php_printf( "Usage: %s [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p <prefix>] [-g <pid>] [-c <file>] [-d foo[=bar]] [-y <file>]\n"
917+
php_printf( "Usage: %s [-n] [-e] [-h] [-i] [-m] [-v] [-t] [-p <prefix>] [-g <pid>] [-c <file>] [-d foo[=bar]] [-y <file>] [-D] [-F]\n"
916918
" -c <path>|<file> Look for php.ini file in this directory\n"
917919
" -n No php.ini file will be used\n"
918920
" -d foo[=bar] Define INI entry foo with value 'bar'\n"
@@ -928,6 +930,9 @@ static void php_cgi_usage(char *argv0)
928930
" -y, --fpm-config <file>\n"
929931
" Specify alternative path to FastCGI process manager config file.\n"
930932
" -t, --test Test FPM configuration and exit\n"
933+
" -D, --daemonize force to run in background, and ignore daemonize option from config file\n"
934+
" -F, --nodaemonize\n"
935+
" force to stay in foreground, and ignore daemonize option from config file\n"
931936
" -R, --allow-to-run-as-root\n"
932937
" Allow pool to run as root (disabled by default)\n",
933938
prog, PHP_PREFIX);
@@ -1550,6 +1555,7 @@ int main(int argc, char *argv[])
15501555
char *fpm_prefix = NULL;
15511556
char *fpm_pid = NULL;
15521557
int test_conf = 0;
1558+
int force_daemon = -1;
15531559
int php_information = 0;
15541560
int php_allow_to_run_as_root = 0;
15551561

@@ -1670,6 +1676,14 @@ int main(int argc, char *argv[])
16701676
php_allow_to_run_as_root = 1;
16711677
break;
16721678

1679+
case 'D': /* daemonize */
1680+
force_daemon = 1;
1681+
break;
1682+
1683+
case 'F': /* nodaemonize */
1684+
force_daemon = 0;
1685+
break;
1686+
16731687
default:
16741688
case 'h':
16751689
case '?':
@@ -1797,7 +1811,7 @@ consult the installation file that came with this distribution, or visit \n\
17971811
}
17981812
}
17991813

1800-
if (0 > fpm_init(argc, argv, fpm_config ? fpm_config : CGIG(fpm_config), fpm_prefix, fpm_pid, test_conf, php_allow_to_run_as_root)) {
1814+
if (0 > fpm_init(argc, argv, fpm_config ? fpm_config : CGIG(fpm_config), fpm_prefix, fpm_pid, test_conf, php_allow_to_run_as_root, force_daemon)) {
18011815

18021816
if (fpm_globals.send_config_pipe[1]) {
18031817
int writeval = 0;

sapi/fpm/init.d.php-fpm.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ case "$1" in
5454
start)
5555
echo -n "Starting php-fpm "
5656

57-
$php_fpm_BIN $php_opts
57+
$php_fpm_BIN --daemonize $php_opts
5858

5959
if [ "$?" != 0 ] ; then
6060
echo " failed"

sapi/fpm/php-fpm.8.in

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ Test FPM configuration file and exit
9999
If called twice (-tt), the configuration is dumped before exiting.
100100
.TP
101101
.PD 0
102+
.B \-\-daemonize
103+
.TP
104+
.PD 1
105+
.B \-D
106+
Force to run in background and ignore daemonize option from configuration file.
107+
.TP
108+
.PD 0
109+
.B \-\-nodaemonize
110+
.TP
111+
.PD 1
112+
.B \-F
113+
Force to stay in foreground and ignore daemonize option from configuration file.
114+
.TP
115+
.PD 0
102116
.B \-\-zend\-extension \fIfile\fP
103117
.TP
104118
.PD 1
@@ -113,13 +127,20 @@ The configuration file for the php-fpm daemon.
113127
.B php.ini
114128
The standard php configuration file.
115129
.SH EXAMPLES
116-
You should use the init script provided to start and stop the php-fpm daemon. This situation applies for any unix systems which use init.d for their main process manager.
130+
For any unix systems which use init.d for their main process manager, you should use the init script provided to start and stop the php-fpm daemon.
117131
.P
118132
.PD 1
119133
.RS
120134
sudo /etc/init.d/php-fpm start
121135
.RE
122136
.TP
137+
For any unix systems which use systemd for their main process manager, you should use the unit file provided to start and stop the php-fpm daemon.
138+
.P
139+
.PD 1
140+
.RS
141+
sudo systemctl start php-fpm.service
142+
.RE
143+
.TP
123144
If your installation has no appropriate init script, launch php-fpm with no arguments. It will launch as a daemon (background process) by default. The file @php_fpm_localstatedir@/run/php-fpm.pid determines whether php-fpm is already up and running. Once started, php-fpm then responds to several POSIX signals:
124145
.P
125146
.PD 0

0 commit comments

Comments
 (0)