1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<!-- splitted from ./en/functions/pcntl.xml, last change in rev 1.2 -->
<refentry id="function.pcntl-signal">
<refnamediv>
<refname>pcntl_signal</refname>
<refpurpose>Installs a signal handler</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>bool</type><methodname>pcntl_signal</methodname>
<methodparam><type>int</type><parameter>signo</parameter></methodparam>
<methodparam><type>callback</type><parameter>handle</parameter></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>restart_syscalls</parameter></methodparam>
</methodsynopsis>
<para>
The <function>pcntl_signal</function> function installs a new
signal handler for the signal indicated by
<parameter>signo</parameter>. The signal handler is set to
<parameter>handler</parameter> which may be the name of a user
created function, or either of the two global constants SIG_IGN
or SIG_DFL. The optional <parameter>restart_syscalls</parameter>
specifies whether system call restarting should be used when this
signal arrives and defaults to &true;.
</para>
<para>
&return.success;
</para>
<note>
<para>
The optional <parameter>restart_syscalls</parameter> parameter became
available in PHP 4.3.0.
</para>
</note>
<note>
<para>
The ability to use an object method as a callback became available in
PHP 4.3.0. Note that when you set a handler to an object method, that
object's reference count is increased which makes it persist until you
either change the handler to something else, or your script ends.
</para>
</note>
<example>
<title><function>pcntl_signal</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
// tick use required as of PHP 4.3.0
declare(ticks = 1);
// signal handler function
function sig_handler($signo)
{
switch ($signo) {
case SIGTERM:
// handle shutdown tasks
exit;
break;
case SIGHUP:
// handle restart tasks
break;
case SIGUSR1:
echo "Caught SIGUSR1...\n";
break;
default:
// handle all other signals
}
}
echo "Installing signal handler...\n";
// setup signal handlers
pcntl_signal(SIGTERM, "sig_handler");
pcntl_signal(SIGHUP, "sig_handler");
pcntl_signal(SIGUSR1, "sig_handler");
// or use an object, available as of PHP 4.3.0
// pcntl_signal(SIGUSR1, array($obj, "do_something");
echo"Generating signal SIGTERM to self...\n";
// send SIGUSR1 to current process id
posix_kill(posix_getpid(), SIGUSR1);
echo "Done\n"
?>
]]>
</programlisting>
</example>
<note>
<para>
As of PHP 4.3.0 PCNTL uses ticks as the signal handle callback mechanism,
which is much faster than the previous mechanism. This change follows the
same semantics as using
"<link linkend="control-structures.declare.ticks">user ticks</link>". You
must use the <link linkend="control-structures.declare">declare()</link>
statement to specify the locations in your program where callbacks are
allowed to occur for the signal handler to function properly (as used in
the above example).
</para>
</note>
<para>
See also <function>pcntl_fork</function> and
<function>pcntl_waitpid</function>.
</para>
</refsect1>
</refentry>
<!-- 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:"../../../../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
-->
|