From 6ea61098bde1984cb069cf6448fc991a496324ba Mon Sep 17 00:00:00 2001 From: Daniel Beckham Date: Fri, 28 Sep 2001 21:40:05 +0000 Subject: [PATCH] completed intro text, added a couple of function examples git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@58673 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/pcntl.xml | 65 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/functions/pcntl.xml b/functions/pcntl.xml index 2d89181710..c944a38f83 100644 --- a/functions/pcntl.xml +++ b/functions/pcntl.xml @@ -1,9 +1,25 @@ - + Process Control Functions PCNTL + + Process Control support in PHP implements the Unix style of + process creation, program execution, signal handling and process + termination. Process Control should not be enabled within a + webserver environment and unexpected results may happen if any + Process Control functions are used within a webserver environment. + + + This documentation is intended to explain the general usage of + each of the Process Control functions. For detailed information + about Unix process control you are encouraged to consult your + systems documentation including fork(2), waitpid(2) and signal(2) + or a comprehensive reference such as Advanced + Programming in the UNIX Environment by W. Richard Stevens + (Addison-Wesley). + Process Control support in PHP is not enabled by default. You will need to use the - Process Control Example @@ -176,6 +191,23 @@ function sig_handler($signo) { parent's context, no child process will be created, and a PHP error is raised. + + <function>pcntl_fork</function> Example + +<?php + +$pid = pcntl_fork(); +if ($pid == -1) { + die("could not fork"); +} else if ($pid) { + // we are the parent +} else { + // we are the child +} + +?> + + See also pcntl_waitpid and pcntl_signal. @@ -210,6 +242,35 @@ function sig_handler($signo) { pcntl_signal returns &true; on success or &false; on failure. + + <function>pcntl_fork</function> Example + +<?php + +// setup signal handlers +pcntl_signal(SIGTERM, "sig_handler"); +pcntl_signal(SIGHUP, "sig_handler"); + +// signal handler function +function sig_handler($signo) { + + switch($signo) { + case SIGTERM: + // handle shutdown tasks + exit; + break; + case SIGHUP: + // handle restart tasks + break; + default: + // handle all other signals + } + +} + +?> + + See also pcntl_fork and pcntl_waitpid.