mirror of
https://github.com/php/doc-zh.git
synced 2026-04-29 19:23:39 +02:00
dd0fc99232
* Update constants.xml * Update ini.xml * Update sys-getloadavg.xml * Update time-sleep-until.xml * Update define.xml * Update highlight-file.xml * Update time-nanosleep.xml * Update connection-aborted.xml * Update hrtime.xml * Update connection-status.xml * Update uniqid.xml * Update halt-compiler.xml * Update sleep.xml * Update highlight-string.xml * Update ignore-user-abort.xml * Update get-browser.xml * Update usleep.xml * Update php-strip-whitespace.xml * Update constant.xml * Update get-browser.xml * Update highlight-file.xml * Update hrtime.xml * Update ignore-user-abort.xml * Update sleep.xml * Update sys-getloadavg.xml
154 lines
3.7 KiB
XML
154 lines
3.7 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 0abd79a0d9d783d492a2c61b834a4ded74bc7145 Maintainer: daijie Status: ready -->
|
|
<!-- CREDITS: mowangjuanzi -->
|
|
<refentry xml:id="function.sleep" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>sleep</refname>
|
|
<refpurpose>延缓执行</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>int</type><methodname>sleep</methodname>
|
|
<methodparam><type>int</type><parameter>seconds</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>
|
|
程序延迟执行指定的 <parameter>seconds</parameter> 的秒数。
|
|
</simpara>
|
|
<note>
|
|
<para>
|
|
为了让程序执行延迟几分之一秒,应使用 <function>usleep</function>,因为 <function>sleep</function>
|
|
需要 &integer;。例如 <code>sleep(0.25)</code> 会使程序暂停 <literal>0</literal> 秒。
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>seconds</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
暂停的秒数(必须大于或等于 <literal>0</literal>)。
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
成功时返回 0。
|
|
</para>
|
|
<para>
|
|
如果函数的调用被一个信号中止,<function>sleep</function> 会返回一个非零的值。在
|
|
Windows 上,该值总是 <literal>192</literal>(即 Windows API 常量
|
|
<constant>WAIT_IO_COMPLETION</constant> 的值)。其他平台上,该返回值是剩余未 sleep 的秒数。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
如果指定的 <parameter>seconds</parameter> 是负数,该函数会抛出 <classname>ValueError</classname>。
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.0.0</entry>
|
|
<entry>
|
|
此函数在负数 <parameter>seconds</parameter> 时抛出 <classname>ValueError</classname>,之前会引发
|
|
<constant>E_WARNING</constant> 且函数返回 &false;。
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title><function>sleep</function> 示例</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
// 当前时间
|
|
echo date('h:i:s') . "\n";
|
|
|
|
// 睡眠 10 秒
|
|
sleep(10);
|
|
|
|
// 醒来!
|
|
echo date('h:i:s') . "\n";
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
该例子会在休眠10秒后输出。
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
05:31:23
|
|
05:31:33
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>usleep</function></member>
|
|
<member><function>time_nanosleep</function></member>
|
|
<member><function>time_sleep_until</function></member>
|
|
<member><function>set_time_limit</function></member>
|
|
</simplelist>
|
|
</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:"~/.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
|
|
-->
|