-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathuniqid.xml
137 lines (129 loc) · 3.99 KB
/
uniqid.xml
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
133
134
135
136
137
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: b65b98da1039e01b4a8f51f94560822ec9a113d9 Maintainer: daijie Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<refentry xml:id="function.uniqid" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>uniqid</refname>
<refpurpose>生成基于时间的标识符</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>uniqid</methodname>
<methodparam choice="opt"><type>string</type><parameter>prefix</parameter><initializer>""</initializer></methodparam>
<methodparam choice="opt"><type>bool</type><parameter>more_entropy</parameter><initializer>&false;</initializer></methodparam>
</methodsynopsis>
<para>
获取基于当前时间的标识符,精度为微秒,以指定 <parameter>prefix</parameter> 作为前缀,并可选择附加随机生成的值。
</para>
&caution.cryptographically-insecure;
<warning>
<para>
该函数不保证返回值的唯一性,因为该值基于当前时间(以微秒为单位)或当前时间加上少量随机数据(如果
<parameter>more_entropy</parameter> 为 &true;)。
</para>
</warning>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>prefix</parameter></term>
<listitem>
<para>
有用的参数。例如同一微秒时在多台主机上同时生成标识符。(如果系统时钟向后移动,例如通过 NTP 调整,即使在单个主机上也会发生这种情况。)
</para>
<para>
<parameter>prefix</parameter>为空,则返回的字符串长度为
13。<parameter>more_entropy</parameter> 为 &true;,则返回的字符串长度为 23。
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>more_entropy</parameter></term>
<listitem>
<para>
如果设置为 &true;,<function>uniqid</function>
会在返回的字符串结尾增加额外的熵(使用线性同余组合发生器)。
使得唯一ID更具唯一性。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
返回字符串形式的,基于时间戳的标识符。
</para>
<warning>
<para>
该函数不保证返回值的唯一性。
</para>
</warning>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>uniqid</function> 示例</title>
<programlisting role="php">
<![CDATA[
<?php
/* 一个 uniqid,像:4b3403665fea6 */
printf("uniqid(): %s\r\n", uniqid());
/* 也可以为 uniqid 添加前缀,以下两种方式相同:
*
* $uniqid = $prefix . uniqid();
* $uniqid = uniqid($prefix);
*/
printf("uniqid('php_'): %s\r\n", uniqid('php_'));
/* 还可以启用 more_entropy 参数,在
* 某些系统上是必须的,比如 Cygwin。这使得 uniqid()
* 产生如下值:4b340550242239.64159797
*/
printf("uniqid('', true): %s\r\n", uniqid('', true));
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="notes">
&reftitle.notes;
<note>
<para>
在 Cygwin 环境下,为了使此函数能够工作,<parameter>more_entropy</parameter> 必须设置为 &true;。
</para>
</note>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><function>random_bytes</function></member>
</simplelist>
</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
-->