danbeck Fri Sep 28 17:40:05 2001 EDT
Modified files:
/phpdoc/en/functions pcntl.xml
Log:
completed intro text, added a couple of function examples
Index: phpdoc/en/functions/pcntl.xml
diff -u phpdoc/en/functions/pcntl.xml:1.3 phpdoc/en/functions/pcntl.xml:1.4
--- phpdoc/en/functions/pcntl.xml:1.3 Fri Sep 21 18:47:45 2001
+++ phpdoc/en/functions/pcntl.xml Fri Sep 28 17:40:05 2001
@@ -1,10 +1,26 @@
<?xml encoding="iso-8859-1"?>
-<!-- $Revision: 1.3 $ -->
+<!-- $Revision: 1.4 $ -->
<reference id="ref.pcntl">
<title>Process Control Functions</title>
<titleabbrev>PCNTL</titleabbrev>
<partintro>
<para>
+ 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.
+ </para>
+ <para>
+ 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 <citation>Advanced
+ Programming in the UNIX Environment by W. Richard Stevens
+ (Addison-Wesley)</citation>.
+ </para>
+ <para>
Process Control support in PHP is not enabled by default. You
will need to use the <link
linkend="install.configure.enable-pcntl">--enable-pcntl</link>
@@ -89,7 +105,6 @@
</table>
</para>
-
<sect1 id="pcntl-example">
<title>Process Control Example</title>
<para>
@@ -176,6 +191,23 @@
parent's context, no child process will be created, and a PHP
error is raised.
</para>
+ <example>
+ <title><function>pcntl_fork</function> Example</title>
+ <programlisting role="php">
+<?php
+
+$pid = pcntl_fork();
+if ($pid == -1) {
+ die("could not fork");
+} else if ($pid) {
+ // we are the parent
+} else {
+ // we are the child
+}
+
+?>
+ </programlisting>
+ </example>
<para>
See also <function>pcntl_waitpid</function> and
<function>pcntl_signal</function>.
@@ -210,6 +242,35 @@
<function>pcntl_signal</function> returns &true; on success or
&false; on failure.
</para>
+ <example>
+ <title><function>pcntl_fork</function> Example</title>
+ <programlisting role="php">
+<?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
+ }
+
+}
+
+?>
+ </programlisting>
+ </example>
<para>
See also <function>pcntl_fork</function> and
<function>pcntl_waitpid</function>.