reference/datetime/functions/microtime.xml
5c951013ca04161992efed8b86fb40f55669958e
...
...
@@ -9,14 +9,17 @@
9
9
<refsect1 role="description">
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
-
<type>mixed</type><methodname>microtime</methodname>
13
-
<methodparam choice="opt"><type>bool</type><parameter>get_as_float</parameter><initializer>false</initializer></methodparam>
12
+
<type class="union"><type>string</type><type>float</type></type><methodname>microtime</methodname>
13
+
<methodparam choice="opt"><type>bool</type><parameter>as_float</parameter><initializer>&false;</initializer></methodparam>
14
14
</methodsynopsis>
15
15
<para>
16
16
<function>microtime</function> returns the current Unix timestamp with
17
17
microseconds. This function is only available on operating systems that
18
18
support the gettimeofday() system call.
19
19
</para>
20
+
<para>
21
+
For performance measurements, using <function>hrtime</function> is recommended.
22
+
</para>
20
23
</refsect1>
21
24

22
25
<refsect1 role="parameters">
...
...
@@ -24,7 +27,7 @@
24
27
<para>
25
28
<variablelist>
26
29
<varlistentry>
27
-
<term><parameter>get_as_float</parameter></term>
30
+
<term><parameter>as_float</parameter></term>
28
31
<listitem>
29
32
<para>
30
33
If used and set to &true;, <function>microtime</function> will return a
...
...
@@ -44,10 +47,10 @@
44
47
the form "msec sec", where <literal>sec</literal> is the number of seconds
45
48
since the Unix epoch (0:00:00 January 1,1970 GMT), and <literal>msec</literal>
46
49
measures microseconds that have elapsed since <literal>sec</literal>
47
-
and is also expressed in seconds.
50
+
and is also expressed in seconds as a decimal fraction.
48
51
</para>
49
52
<para>
50
-
If <parameter>get_as_float</parameter> is set to &true;, then
53
+
If <parameter>as_float</parameter> is set to &true;, then
51
54
<function>microtime</function> returns a <type>float</type>, which
52
55
represents the current time in seconds since the Unix epoch accurate to the
53
56
nearest microsecond.
...
...
@@ -58,34 +61,7 @@
58
61
&reftitle.examples;
59
62
<para>
60
63
<example>
61
-
<title>Timing script execution with <function>microtime</function></title>
62
-
<programlisting role="php">
63
-
<![CDATA[
64
-
<?php
65
-
/**
66
-
* Simple function to replicate PHP 5 behaviour
67
-
*/
68
-
function microtime_float()
69
-
{
70
-
list($usec, $sec) = explode(" ", microtime());
71
-
return ((float)$usec + (float)$sec);
72
-
}
73
-

74
-
$time_start = microtime_float();
75
-

76
-
// Sleep for a while
77
-
usleep(100);
78
-

79
-
$time_end = microtime_float();
80
-
$time = $time_end - $time_start;
81
-

82
-
echo "Did nothing in $time seconds\n";
83
-
?>
84
-
]]>
85
-
</programlisting>
86
-
</example>
87
-
<example>
88
-
<title>Timing script execution in PHP 5</title>
64
+
<title>Timing script execution</title>
89
65
<programlisting role="php">
90
66
<![CDATA[
91
67
<?php
...
...
@@ -103,14 +79,14 @@ echo "Did nothing in $time seconds\n";
103
79
</programlisting>
104
80
</example>
105
81
<example>
106
-
<title><function>microtime</function> and <literal>REQUEST_TIME_FLOAT</literal> (as of PHP 5.4.0)</title>
82
+
<title><function>microtime</function> and <literal>REQUEST_TIME_FLOAT</literal></title>
107
83
<programlisting role="php">
108
84
<![CDATA[
109
85
<?php
110
86
// Randomize sleeping time
111
87
usleep(mt_rand(100, 10000));
112
88

113
-
// As of PHP 5.4.0, REQUEST_TIME_FLOAT is available in the $_SERVER superglobal array.
89
+
// REQUEST_TIME_FLOAT is available in the $_SERVER superglobal array.
114
90
// It contains the timestamp of the start of the request with microsecond precision.
115
91
$time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
116
92

...
...
@@ -127,11 +103,11 @@ echo "Did nothing in $time seconds\n";
127
103
<para>
128
104
<simplelist>
129
105
<member><function>time</function></member>
106
+
<member><function>hrtime</function></member>
130
107
</simplelist>
131
108
</para>
132
109
</refsect1>
133
110
</refentry>
134
-

135
111
<!-- Keep this comment at the end of the file
136
112
Local variables:
137
113
mode: sgml
138
114