Back to index

php5  5.3.10
Defines | Enumerations | Functions
fpm_process_ctl.h File Reference
#include "fpm_events.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define FPM_MAX_SPAWN_RATE   (32)
#define FPM_IDLE_SERVER_MAINTENANCE_HEARTBEAT   (1000)
#define FPM_PCTL_MIN_HEARTBEAT   (130)

Enumerations

enum  {
  FPM_PCTL_STATE_UNSPECIFIED, FPM_PCTL_STATE_NORMAL, FPM_PCTL_STATE_RELOADING, FPM_PCTL_STATE_TERMINATING,
  FPM_PCTL_STATE_FINISHING
}
enum  { FPM_PCTL_ACTION_SET, FPM_PCTL_ACTION_TIMEOUT, FPM_PCTL_ACTION_LAST_CHILD_EXITED }
enum  { FPM_PCTL_TERM, FPM_PCTL_STOP, FPM_PCTL_CONT, FPM_PCTL_QUIT }

Functions

void fpm_pctl (int new_state, int action)
int fpm_pctl_can_spawn_children ()
int fpm_pctl_kill (pid_t pid, int how)
void fpm_pctl_kill_all (int signo)
void fpm_pctl_heartbeat (struct fpm_event_s *ev, short which, void *arg)
void fpm_pctl_perform_idle_server_maintenance_heartbeat (struct fpm_event_s *ev, short which, void *arg)
void fpm_pctl_on_socket_accept (struct fpm_event_s *ev, short which, void *arg)
int fpm_pctl_child_exited ()
int fpm_pctl_init_main ()

Define Documentation

Definition at line 13 of file fpm_process_ctl.h.

#define FPM_MAX_SPAWN_RATE   (32)

Definition at line 11 of file fpm_process_ctl.h.

#define FPM_PCTL_MIN_HEARTBEAT   (130)

Definition at line 15 of file fpm_process_ctl.h.


Enumeration Type Documentation

anonymous enum
Enumerator:
FPM_PCTL_STATE_UNSPECIFIED 
FPM_PCTL_STATE_NORMAL 
FPM_PCTL_STATE_RELOADING 
FPM_PCTL_STATE_TERMINATING 
FPM_PCTL_STATE_FINISHING 

Definition at line 31 of file fpm_process_ctl.h.

anonymous enum
Enumerator:
FPM_PCTL_ACTION_SET 
FPM_PCTL_ACTION_TIMEOUT 
FPM_PCTL_ACTION_LAST_CHILD_EXITED 

Definition at line 39 of file fpm_process_ctl.h.

anonymous enum
Enumerator:
FPM_PCTL_TERM 
FPM_PCTL_STOP 
FPM_PCTL_CONT 
FPM_PCTL_QUIT 

Definition at line 45 of file fpm_process_ctl.h.


Function Documentation

void fpm_pctl ( int  new_state,
int  action 
)

Definition at line 203 of file fpm_process_ctl.c.

{
       switch (action) {
              case FPM_PCTL_ACTION_SET :
                     if (fpm_state == new_state) { /* already in progress - just ignore duplicate signal */
                            return;
                     }

                     switch (fpm_state) { /* check which states can be overridden */
                            case FPM_PCTL_STATE_NORMAL :
                                   /* 'normal' can be overridden by any other state */
                                   break;
                            case FPM_PCTL_STATE_RELOADING :
                                   /* 'reloading' can be overridden by 'finishing' */
                                   if (new_state == FPM_PCTL_STATE_FINISHING) break;
                            case FPM_PCTL_STATE_FINISHING :
                                   /* 'reloading' and 'finishing' can be overridden by 'terminating' */
                                   if (new_state == FPM_PCTL_STATE_TERMINATING) break;
                            case FPM_PCTL_STATE_TERMINATING :
                                   /* nothing can override 'terminating' state */
                                   zlog(ZLOG_DEBUG, "not switching to '%s' state, because already in '%s' state",
                                          fpm_state_names[new_state], fpm_state_names[fpm_state]);
                                   return;
                     }

                     fpm_signal_sent = 0;
                     fpm_state = new_state;

                     zlog(ZLOG_DEBUG, "switching to '%s' state", fpm_state_names[fpm_state]);
                     /* fall down */

              case FPM_PCTL_ACTION_TIMEOUT :
                     fpm_pctl_action_next();
                     break;
              case FPM_PCTL_ACTION_LAST_CHILD_EXITED :
                     fpm_pctl_action_last();
                     break;

       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 245 of file fpm_process_ctl.c.

Here is the caller graph for this function:

Definition at line 251 of file fpm_process_ctl.c.

{
       if (fpm_state == FPM_PCTL_STATE_NORMAL) {
              return 0;
       }

       if (!fpm_globals.running_children) {
              fpm_pctl(FPM_PCTL_STATE_UNSPECIFIED, FPM_PCTL_ACTION_LAST_CHILD_EXITED);
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fpm_pctl_heartbeat ( struct fpm_event_s ev,
short  which,
void *  arg 
)

Definition at line 441 of file fpm_process_ctl.c.

{
       static struct fpm_event_s heartbeat;
       struct timeval now;

       if (fpm_globals.parent_pid != getpid()) {
              return; /* sanity check */
       }

       if (which == FPM_EV_TIMEOUT) {
              fpm_clock_get(&now);
              fpm_pctl_check_request_timeout(&now);
              return;
       }

       /* ensure heartbeat is not lower than FPM_PCTL_MIN_HEARTBEAT */
       fpm_globals.heartbeat = MAX(fpm_globals.heartbeat, FPM_PCTL_MIN_HEARTBEAT);

       /* first call without setting to initialize the timer */
       zlog(ZLOG_DEBUG, "heartbeat have been set up with a timeout of %dms", fpm_globals.heartbeat);
       fpm_event_set_timer(&heartbeat, FPM_EV_PERSIST, &fpm_pctl_heartbeat, NULL);
       fpm_event_add(&heartbeat, fpm_globals.heartbeat);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 264 of file fpm_process_ctl.c.

{
       int i;

       saved_argc = fpm_globals.argc;
       saved_argv = malloc(sizeof(char *) * (saved_argc + 1));

       if (!saved_argv) {
              return -1;
       }

       for (i = 0; i < saved_argc; i++) {
              saved_argv[i] = strdup(fpm_globals.argv[i]);

              if (!saved_argv[i]) {
                     return -1;
              }
       }

       saved_argv[i] = 0;

       if (0 > fpm_cleanup_add(FPM_CLEANUP_ALL, fpm_pctl_cleanup, 0)) {
              return -1;
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int fpm_pctl_kill ( pid_t  pid,
int  how 
)

Definition at line 122 of file fpm_process_ctl.c.

{
       int s = 0;

       switch (how) {
              case FPM_PCTL_TERM :
                     s = SIGTERM;
                     break;
              case FPM_PCTL_STOP :
                     s = SIGSTOP;
                     break;
              case FPM_PCTL_CONT :
                     s = SIGCONT;
                     break;
              case FPM_PCTL_QUIT :
                     s = SIGQUIT;
                     break;
              default :
                     break;
       }
       return kill(pid, s);
}

Here is the caller graph for this function:

void fpm_pctl_kill_all ( int  signo)

Definition at line 146 of file fpm_process_ctl.c.

{
       struct fpm_worker_pool_s *wp;
       int alive_children = 0;

       for (wp = fpm_worker_all_pools; wp; wp = wp->next) {
              struct fpm_child_s *child;

              for (child = wp->children; child; child = child->next) {
                     int res = kill(child->pid, signo);

                     zlog(ZLOG_DEBUG, "[pool %s] sending signal %d %s to child %d",
                            child->wp->config->name, signo,
                            fpm_signal_names[signo] ? fpm_signal_names[signo] : "", (int) child->pid);

                     if (res == 0) {
                            ++alive_children;
                     }
              }
       }

       if (alive_children) {
              zlog(ZLOG_DEBUG, "%d child(ren) still alive", alive_children);
       }
}

Here is the caller graph for this function:

void fpm_pctl_on_socket_accept ( struct fpm_event_s ev,
short  which,
void *  arg 
)

Definition at line 496 of file fpm_process_ctl.c.

{
       struct fpm_worker_pool_s *wp = (struct fpm_worker_pool_s *)arg;
       struct fpm_child_s *child;


       if (fpm_globals.parent_pid != getpid()) {
              /* prevent a event race condition when child process
               * have not set up its own event loop */
              return;
       }

       wp->socket_event_set = 0;

/*     zlog(ZLOG_DEBUG, "[pool %s] heartbeat running_children=%d", wp->config->name, wp->running_children);*/

       if (wp->running_children >= wp->config->pm_max_children) {
              if (!wp->warn_max_children) {
                     fpm_scoreboard_update(0, 0, 0, 0, 0, 1, FPM_SCOREBOARD_ACTION_INC, wp->scoreboard);
                     zlog(ZLOG_WARNING, "[pool %s] server reached max_children setting (%d), consider raising it", wp->config->name, wp->config->pm_max_children);
                     wp->warn_max_children = 1;
              }

              return;
       }

       for (child = wp->children; child; child = child->next) {
              /* if there is at least on idle child, it will handle the connection, stop here */
              if (fpm_request_is_idle(child)) {
                     return;
              }
       }

       wp->warn_max_children = 0;
       fpm_children_make(wp, 1, 1, 1);

       if (fpm_globals.is_child) {
              return;
       }

       zlog(ZLOG_DEBUG, "[pool %s] got accept without idle child available .... I forked", wp->config->name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fpm_pctl_perform_idle_server_maintenance_heartbeat ( struct fpm_event_s ev,
short  which,
void *  arg 
)

Definition at line 466 of file fpm_process_ctl.c.

{
       static struct fpm_event_s heartbeat;
       struct timeval now;

       if (fpm_globals.parent_pid != getpid()) {
              return; /* sanity check */
       }

       if (which == FPM_EV_TIMEOUT) {
              fpm_clock_get(&now);
              if (fpm_pctl_can_spawn_children()) {
                     fpm_pctl_perform_idle_server_maintenance(&now);

                     /* if it's a child, stop here without creating the next event
                      * this event is reserved to the master process
                      */
                     if (fpm_globals.is_child) {
                            return;
                     }
              }
              return;
       }

       /* first call without setting which to initialize the timer */
       fpm_event_set_timer(&heartbeat, FPM_EV_PERSIST, &fpm_pctl_perform_idle_server_maintenance_heartbeat, NULL);
       fpm_event_add(&heartbeat, FPM_IDLE_SERVER_MAINTENANCE_HEARTBEAT);
}

Here is the call graph for this function:

Here is the caller graph for this function: