Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 8750

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>pcntl_signal</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="Process Control Functions"
HREF="ref.pcntl.html"><LINK
REL="PREVIOUS"
TITLE="pcntl_setpriority"
HREF="function.pcntl-setpriority.html"><LINK
REL="NEXT"
TITLE="pcntl_wait"
HREF="function.pcntl-wait.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>PHP 手册</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.pcntl-setpriority.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.pcntl-wait.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.pcntl-signal"
></A
>pcntl_signal</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN170047"
></A
><P
>    (PHP 4 &#62;= 4.1.0, PHP 5)</P
>pcntl_signal&nbsp;--&nbsp;Installs a signal handler</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN170050"
></A
><H2
>说明</H2
>bool <B
CLASS="methodname"
>pcntl_signal</B
> ( int signo, callback handler [, bool restart_syscalls] )<BR
></BR
><P
>&#13;   The <B
CLASS="function"
>pcntl_signal()</B
> function installs a new
   signal handler for the signal indicated by <CODE
CLASS="parameter"
>signo</CODE
>.   
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN170067"
></A
><H2
>参数</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>signo</CODE
></DT
><DD
><P
>&#13;       The signal number.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>handler</CODE
></DT
><DD
><P
>&#13;       The signal handler which may be the name of a user created function,
       or method, or either of the two global constants 
       <TT
CLASS="constant"
><B
>SIG_IGN</B
></TT
> or <TT
CLASS="constant"
><B
>SIG_DFL</B
></TT
>. 
      </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
        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.
       </P
></BLOCKQUOTE
></DIV
></DD
><DT
><CODE
CLASS="parameter"
>restart_syscalls</CODE
></DT
><DD
><P
>&#13;       Specifies whether system call restarting should be used when this
       signal arrives and defaults to <TT
CLASS="constant"
><B
>TRUE</B
></TT
>.
      </P
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN170091"
></A
><H2
>返回值</H2
><P
>&#13;   如果成功则返回 <TT
CLASS="constant"
><B
>TRUE</B
></TT
>,失败则返回 <TT
CLASS="constant"
><B
>FALSE</B
></TT
>。
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN170096"
></A
><H2
>更新日志</H2
><P
>&#13;   <DIV
CLASS="informaltable"
><P
></P
><A
NAME="AEN170099"
></A
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>版本</TH
><TH
>说明</TH
></TR
></THEAD
><TBODY
><TR
><TD
>4.3.0</TD
><TD
>&#13;        The <CODE
CLASS="parameter"
>restart_syscalls</CODE
> parameter was added.
       </TD
></TR
><TR
><TD
>4.3.0</TD
><TD
>&#13;        The ability to use an object method as a callback became available.
       </TD
></TR
><TR
><TD
>4.3.0</TD
><TD
>&#13;        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
        "<A
HREF="control-structures.declare.html#control-structures.declare.ticks"
>user ticks</A
>".
        You must use the <A
HREF="control-structures.declare.html"
>declare()</A
> 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).
       </TD
></TR
></TBODY
></TABLE
><P
></P
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN170118"
></A
><H2
>范例</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN170121"
></A
><P
><B
>例 1. <B
CLASS="function"
>pcntl_signal()</B
> example</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#FF8000">// tick use required as of PHP 4.3.0<br /></font><font color="#007700">declare(</font><font color="#0000BB">ticks </font><font color="#007700">= </font><font color="#0000BB">1</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// signal handler function<br /></font><font color="#007700">function </font><font color="#0000BB">sig_handler</font><font color="#007700">(</font><font color="#0000BB">$signo</font><font color="#007700">)<br />{<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch (</font><font color="#0000BB">$signo</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case </font><font color="#0000BB">SIGTERM</font><font color="#007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// handle shutdown tasks<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">exit;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case </font><font color="#0000BB">SIGHUP</font><font color="#007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// handle restart tasks<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case </font><font color="#0000BB">SIGUSR1</font><font color="#007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"Caught SIGUSR1...\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">// handle all other signals<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">}<br /><br />}<br /><br />echo </font><font color="#DD0000">"Installing signal handler...\n"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// setup signal handlers<br /></font><font color="#0000BB">pcntl_signal</font><font color="#007700">(</font><font color="#0000BB">SIGTERM</font><font color="#007700">, </font><font color="#DD0000">"sig_handler"</font><font color="#007700">);<br /></font><font color="#0000BB">pcntl_signal</font><font color="#007700">(</font><font color="#0000BB">SIGHUP</font><font color="#007700">,&nbsp;&nbsp;</font><font color="#DD0000">"sig_handler"</font><font color="#007700">);<br /></font><font color="#0000BB">pcntl_signal</font><font color="#007700">(</font><font color="#0000BB">SIGUSR1</font><font color="#007700">, </font><font color="#DD0000">"sig_handler"</font><font color="#007700">);<br /><br /></font><font color="#FF8000">// or use an object, available as of PHP 4.3.0<br />// pcntl_signal(SIGUSR1, array($obj, "do_something");<br /><br /></font><font color="#007700">echo</font><font color="#DD0000">"Generating signal SIGTERM to self...\n"</font><font color="#007700">;<br /><br /></font><font color="#FF8000">// send SIGUSR1 to current process id<br /></font><font color="#0000BB">posix_kill</font><font color="#007700">(</font><font color="#0000BB">posix_getpid</font><font color="#007700">(), </font><font color="#0000BB">SIGUSR1</font><font color="#007700">);<br /><br />echo </font><font color="#DD0000">"Done\n"<br /><br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN170125"
></A
><H2
>参见</H2
><P
>&#13;   <P
></P
><TABLE
BORDER="0"
><TBODY
><TR
><TD
><A
HREF="function.pcntl-fork.html"
><B
CLASS="function"
>pcntl_fork()</B
></A
></TD
></TR
><TR
><TD
><A
HREF="function.pcntl-waitpid.html"
><B
CLASS="function"
>pcntl_waitpid()</B
></A
></TD
></TR
></TBODY
></TABLE
><P
></P
>
  </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.pcntl-setpriority.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>起始页</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.pcntl-wait.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>pcntl_setpriority</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.pcntl.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>pcntl_wait</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>