fpm_init
2015-11-04 14:23:07 0 举报
`fpm_init`是一个函数或方法,用于初始化FPM(FastCGI Process Manager)进程。FPM是一个自由软件,用于管理PHP FastCGI进程群组。在Web服务器和应用程序服务器之间,FPM提供了一个轻量级的接口,使得PHP应用程序可以更高效地运行。通过调用`fpm_init`函数,可以启动一个新的FPM进程,或者重新初始化现有的进程。这个函数通常需要一些参数,例如进程ID、配置文件路径等,以便正确地配置和管理FPM进程。总之,`fpm_init`是FPM框架中的一个重要组件,它负责创建和管理PHP FastCGI进程,从而提高了PHP应用程序的性能和稳定性。
作者其他创作
大纲/内容
for (wp = fpm_worker_all_pools; wp; wp = wp-next) {if (0 fpm_env_conf_wp(wp)) {
/* pm */if (wp-config-pm != PM_STYLE_STATIC && wp-config-pm != PM_STYLE_DYNAMIC && wp-config-pm != PM_STYLE_ONDEMAND) {
if (0 fpm_stdio_open_error_log(0))
struct fpm_worker_pool_config_s *config = wp-config;if (!fpm_event_support_edge_trigger()) {if (config-pm_process_idle_timeout listen_backlog listen_backlog = FPM_BACKLOG_DEFAULT;/* certainely useless but proper */config-pm_start_servers = 0;config-pm_min_spare_servers = 0;config-pm_max_spare_servers = 0;
N
int fpm_sockets_init_main()
int fpm_scoreboard_init_main()
struct fpm_event_module_s *fpm_event_poll_module()
for (kv = wp-config-env; kv; kv = kv-next) {if (*kv-value == '$') {char *value = getenv(kv-value + 1);if (!value) {value = \"\
fpm_pagesize = getpagesize();
enum fpm_address_domain fpm_sockets_domain_from_address(char *address)
if (fpm_globals.prefix && *fpm_globals.prefix) {if (!fpm_conf_is_dir(fpm_globals.prefix)) {
fpm_env_init_main()
if (config-pm_min_spare_servers pm_max_spare_servers pm_min_spare_servers config-pm_max_children || config-pm_max_spare_servers config-pm_max_children) {if (config-pm_max_spare_servers pm_min_spare_servers) {if (config-pm_start_servers pm_start_servers = config-pm_min_spare_servers + ((config-pm_max_spare_servers - config-pm_min_spare_servers) / 2);} else if (config-pm_start_servers pm_min_spare_servers || config-pm_start_servers config-pm_max_spare_servers) {
/* security.limit_extensions */if (!wp-config-security_limit_extensions) {wp-config-security_limit_extensions = strdup(\".php .phar\");
static inline int fpm_use_error_log()
fpm_stdio_init_main()
struct fpm_event_module_s *fpm_event_devpoll_module()
return module ? module-support_edge_trigger : 0;
fpm_php_init_main()
struct fpm_event_module_s *fpm_event_port_module()
int fpm_php_init_main()
int fpm_clock_init()
if (pipe(fpm_globals.send_config_pipe) == -1) {pid_t pid = fork();
/* status */if (wp-config-pm_status_path && *wp-config-pm_status_path) {
/* alert if user is not set only if we are not root*/if (!wp-config-user && !geteuid()) {
fpm_scoreboard_init_main()
if (wp-config-group && *wp-config-group) {grp = getgrnam(wp-config-group);wp-set_gid = grp-gr_gid;
/* ping */if (wp-config-ping_path && *wp-config-ping_path) {if (!wp-config-ping_response) {wp-config-ping_response = strdup(\"pong\");
for (i = 0; i fpm_globals.argc; i++) {if (first == NULL) {first = fpm_globals.argv[i];if (last == NULL || fpm_globals.argv[i] == last + 1) {last = fpm_globals.argv[i] + strlen(fpm_globals.argv[i]);if (environ) {for (i = 0; environ[i]; i++) {if (first == NULL) {first = environ[i];if (last == NULL || environ[i] == last + 1) {last = environ[i] + strlen(environ[i]);fpm_env_argv_len = last - first;fpm_env_argv = fpm_globals.argv;
int fpm_signals_init_main()
void fpm_pctl_kill_all(int signo)
static int fpm_conf_process_all_pools()
saved_argc = fpm_globals.argc;saved_argv = malloc(sizeof(char *) * (saved_argc + 1));for (i = 0; i saved_argc; i++) {saved_argv[i] = strdup(fpm_globals.argv[i]);saved_argv[i] = 0;
#if HAVE_PORTreturn &port_module;#else return NULL;
{
if (which != FPM_CLEANUP_PARENT_EXEC) {for (i = 0; i saved_argc; i++) {free(saved_argv[i]);free(saved_argv);
wp-scoreboard-nprocs = wp-config-pm_max_children;
int fpm_unix_init_main()
fpm_conf_post_process(force_daemon TSRMLS_CC)
void fpm_cleanups_run(int type)
if (wp-config-pm_max_children scoreboard) {
if (0 fpm_clock_init()) {
void *fpm_shm_alloc(size_t size)
fpm_conf_process_all_pools()
if (test_conf) {if (test_conf 1) {fpm_conf_dump();fpm_globals.test_successful = 1;
Y
for (wp = fpm_worker_all_pools; wp; wp = wp-next) {
if (0 fpm_systemd_conf())
#ifdef HAVE_TIMES#if (defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK))fpm_scoreboard_tick = sysconf(_SC_CLK_TCK);
if (wp && wp-config) {prefix = wp-config-prefix; /* if the wp prefix is not set */if (prefix == NULL) {prefix = fpm_globals.prefix;/* if the global prefix is not set */if (prefix == NULL) {prefix = default_prefix ? default_prefix : PHP_PREFIX;
if (wp-config-process_priority != 64 && (wp-config-process_priority config-process_priority 20)) {
fpm_event_pre_init(fpm_global_config.events_mechanism)
case 0 : /* children */close(fpm_globals.send_config_pipe[0]); /* close the read side of the pipe */
fpm_pctl_init_main()
fpm_unix_init_main()
for (wp = fpm_worker_all_pools; wp; wp = wp-next) {if (0 fpm_log_write(wp-config-access_format TSRMLS_CC)) {
static int fpm_conf_post_process(int force_daemon TSRMLS_DC)
fpm_children_init_main()
struct fpm_event_module_s *fpm_event_epoll_module()
PHP_FUNCTION(openlog);
#if HAVE_SELECT return &select_module;#else return NULL;
int zlog_set_fd(int new_fd)
fpm_sockets_init_main()
int fpm_event_pre_init(char *machanism)
if (fpm_globals.config == NULL)
void fpm_env_setproctitle(char *title)
if (!fpm_globals.run_as_root) {if (wp-set_uid == 0 || wp-set_gid == 0) {
zlog_fd = new_fd;
int is_root = !geteuid();if (is_root) {
int fd = open(\"/dev/null\
int zlog_set_level(int new_value)
int fpm_log_open(int reopen)
f (force_daemon = 0) {/* forced from command line options */fpm_global_config.daemonize = force_daemon;fpm_globals.log_level = fpm_global_config.log_level;zlog_set_level(fpm_globals.log_level);if (fpm_global_config.process_max 0) {if (fpm_global_config.process_priority != 64 && (fpm_global_config.process_priority 20)) {if (!fpm_global_config.error_log) {fpm_global_config.error_log = strdup(\"log/php-fpm.log\");
int fpm_event_support_edge_trigger()
int fpm_env_init_main()
#if HAVE_DEVPOLL return &devpoll_module;#else return NULL;
ret = fpm_conf_load_ini_file(fpm_globals.config TSRMLS_CC);
wp-scoreboard = fpm_shm_alloc(sizeof(struct fpm_scoreboard_s) + (wp-config-pm_max_children - 1) * sizeof(struct fpm_scoreboard_proc_s *));
switch (pid) {
fpm_log_open(0)
if (!fpm_global_config.syslog_ident) {fpm_global_config.syslog_ident = strdup(\"php-fpm\
static inline void *fpm_array_push(struct fpm_array_s *a)
free(fpm_global_config.pid_file);free(fpm_global_config.error_log);free(fpm_global_config.events_mechanism);fpm_global_config.pid_file = 0;fpm_global_config.error_log = 0;#ifdef HAVE_SYSLOG_Hfree(fpm_global_config.syslog_ident);fpm_global_config.syslog_ident = 0;#endiffree(fpm_globals.config);
if (wp-config-user && *wp-config-user) {pwd = getpwnam(wp-config-user);wp-set_uid = pwd-pw_uid;wp-set_gid = pwd-pw_gid;wp-user = strdup(pwd-pw_name);wp-home = strdup(pwd-pw_dir);
free(last_faults);
#if HAVE_EPOLLreturn &epoll_module;#else return NULL;
/** Return the module configuration*/ struct fpm_event_module_s *fpm_event_kqueue_module()
zlog_level = new_value;
if (fpm_global_config.daemonize) {
static int fpm_unix_conf_wp(struct fpm_worker_pool_s *wp)
int fpm_stdio_init_main()
int fpm_log_write(char *log_format TSRMLS_DC)
int fpm_children_init_main()
ret = (char *) a-data + a-sz * n; return ret;
int fpm_systemd_conf()
fpm_signals_init_main()
static void sig_handler(int signo)
int fpm_conf_load_ini_file(char *filename TSRMLS_DC)
int fpm_pctl_init_main()
TSRMLS_FETCH();php_module_shutdown(TSRMLS_C);sapi_shutdown();
struct fpm_event_module_s *fpm_event_select_module()
#if HAVE_POLL return &poll_module;#else return NULL;
fpm_globals.argc = argc;fpm_globals.argv = argv;if (config && *config) {fpm_globals.config = strdup(config);} fpm_globals.prefix = prefix;fpm_globals.pid = pid;fpm_globals.run_as_root = run_as_root;fpm_globals.force_stderr = force_stderr;
static int fpm_conf_is_dir(char *path)
int fpm_stdio_open_error_log(int reopen)
if (fpm_globals.pid && *fpm_globals.pid) {fpm_global_config.pid_file = strdup(fpm_globals.pid);
struct cleanup_s *c;c = fpm_array_push(&cleanups);
fpm_globals.config = strdup(tmp); efree(tmp);
/* not root *//* set up HOME and USER anyway */pwd = getpwuid(getuid()); wp-user = strdup(pwd-pw_name);wp-home = strdup(pwd-pw_dir);
static int fpm_env_conf_wp(struct fpm_worker_pool_s *wp)
#if HAVE_KQUEUE return &kqueue_module; #else return NULL;
else if (wp-config-pm == PM_STYLE_ONDEMAND) {
for (wp = fpm_worker_all_pools; wp; wp = wp-next) {if (0 fpm_unix_conf_wp(wp)) {
/* continue as a child */setsid();fpm_globals.parent_pid = getpid();
c-type = type;c-cleanup = cleanup;c-arg = arg;
0 条评论
下一页