Index: phpdoc/en/functions/pcntl.xml +++ phpdoc/en/functions/pcntl.xml Process Control Functions PCNTL Process Control support in PHP is not enabled by default. You will need to use the --enable-pcntl configuration option when compiling PHP to enable Process Control support. The following list of signals are supported by the Process Control functions. Please see your systems signal(7) man page for details of the default behavior of these signals.

Supported Signals SIG_IGN SIGFPE SIGCONT SIG_DFL SIGKILL SIGSTOP SIG_ERR SIGUSR1 SIGTSTP SIGHUP SIGUSR2 SIGTTIN SIGINT SIGSEGV SIGTTOU SIGQUIT SIGPIPE SIGURG SIGILL SIGALRM SIGXCPU SIGTRAP SIGTERM SIGXFSZ SIGABRT SIGSTKFLT SIGVTALRM SIGIOT SIGCHLD SIGPROF SIGBUS SIGCLD SIGWINCH SIGPOLL SIGIO SIGPWR SIGSYS
Process Control Example This example forks off a daemon process with a signal handler. Process Control Example <?php $pid = pcntl_fork(); if ($pid == -1) { die("could not fork"); } else if ($pid) { exit(); // we are the parent } else { // we are the child } // detatch from the controlling terminal if (!posix_setsid()) { die("could not detach from terminal"); } // setup signal handlers pcntl_signal(SIGTERM, "sig_handler"); pcntl_signal(SIGHUP, "sig_handler"); // loop forever performing tasks while(1) { // do something interesting here } function sig_handler($signo) { switch($signo) { case SIGTERM: // handle shutdown tasks exit; break; case SIGHUP: // handle restart tasks break; default: // handle all other signals } } ?> pcntl_fork Forks the currently running process Description int pcntl_fork The pcntl_fork function creates a child process that differs from the parent process only in it's PID and PPID. Please see your system's fork(2) man page for specific details as to how fork works on your system. On success, the PID of the child process is returned in the parent's thread of execution, and a 0 is returned in the child's thread of execution. On failure, a -1 will be returned in the parent's context, no child process will be created, and a PHP error is raised. See also pcntl_waitpid and pcntl_signal. pcntl_waitpid Waits on or returns the status of a forked child Description int pcntl_waitpid int pid int status int options The pcntl_waitpid function suspends execution of the current process until a child as specified by the pid argument has exited, or until a signal is delivered whose action is to terminate the current process or to call a signal handling function. If a child as requested by pid has already exited by the time of the call (a so-called "zombie" process), the function returns immediately. Any system resources used by the child are freed. Please see your system's waitpid(2) man page for specific details as to how waitpid works on your system. pcntl_waitpid returns the process ID of the child which exited, -1 on error or zero if WNOHANG was used and no child was available The value of pid can be one of the following: < -1 wait for any child process whose process group ID is equal to the absolute value of pid. -1 wait for any child process; this is the same behaviour that the wait function exhibits. 0 wait for any child process whose process group ID is equal to that of the calling process. > 0 wait for the child whose process ID is equal to the value of pid. pcntl_waitpid will store status information in the status parameter which can be evaluated using the following functions: pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wexitstatus, pcntl_wtermsig and pcntl_wstopsig. The value of options is the value of zero or more of the following two global constants ORed together: WNOHANG return immediately if no child has exited. WUNTRACED return for children which are stopped, and whose status has not been reported. See also pcntl_fork, pcntl_signal, pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wexitstatus, pcntl_wtermsig and pcntl_wstopsig. pcntl_signal Installs a signal handler Description bool pcntl_signal int signo mixed handle The pcntl_signal function installs a new signal handler for the signal indicated by signo. The signal handler is set to handler which may be the name of a user created function, or either of the two global constants SIG_IGN or SIG_DFL. pcntl_signal returns &true; on success or &false; on failure. See also pcntl_fork and pcntl_waitpid.