mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-21 03:18:55 +00:00

on new ability to object method signal calls. Implemented &return.success;. And added tick use to the example (required as of 4.3.0). This essentially closes bug #20189. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@113190 c90b9560-bf6c-de11-be94-00142212c4b1
119 lines
3.3 KiB
XML
119 lines
3.3 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.3 $ -->
|
|
<!-- 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>mixed</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:
|
|
print "Caught SIGUSR1...\n";
|
|
break;
|
|
default:
|
|
// handle all other signals
|
|
}
|
|
|
|
}
|
|
|
|
print "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");
|
|
|
|
print "Generating signal SIGTERM to self...\n";
|
|
|
|
// send SIGUSR1 to current process id
|
|
posix_kill(posix_getpid(), SIGUSR1);
|
|
|
|
print "Done\n"
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<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
|
|
-->
|