mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-27 22:38:55 +00:00

still using this, after discussion on the phpdoc list. From now on, manual.ced will need to be found at ~/.phpdoc/manual.ced. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@288721 c90b9560-bf6c-de11-be94-00142212c4b1
85 lines
1.6 KiB
XML
85 lines
1.6 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<chapter xml:id="pcntl.examples" xmlns="http://docbook.org/ns/docbook">
|
|
&reftitle.examples;
|
|
<section xml:id="pcntl.example">
|
|
<para>
|
|
This example forks off a daemon process with a signal handler.
|
|
</para>
|
|
<example>
|
|
<title>Process Control Example</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
declare(ticks=1);
|
|
|
|
$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() == -1) {
|
|
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
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</section>
|
|
</chapter>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|
|
|