mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-24 07:02:09 +01:00
129 lines
3.9 KiB
XML
129 lines
3.9 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 3a8c3e77df070a046c9d5b56b68926ca2d7e5ee3 Maintainer: leonardolara Status: ready --><!-- CREDITS: felipe,surfmax,fabioluciano,ae,leonardolara -->
|
|
<refentry xml:id="function.microtime" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>microtime</refname>
|
|
<refpurpose>Retorna o timestamp Unix atual com microssegundos</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type class="union"><type>string</type><type>float</type></type><methodname>microtime</methodname>
|
|
<methodparam choice="opt"><type>bool</type><parameter>as_float</parameter><initializer>&false;</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
A função <function>microtime</function> retorna o timestamp atual com
|
|
microssegundos. Esta função está disponível apenas em sistemas operacionais que suportam
|
|
a chamada de sistema gettimeofday().
|
|
</para>
|
|
<para>
|
|
Para medições de desempenho, é recomendado utilizar <function>hrtime</function>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>as_float</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Se utilizada e definida como &true;, a função <function>microtime</function> retornará um
|
|
<type>float</type> em vez de uma <type>string</type>, como descrito na
|
|
seção de valores de retorno a seguir.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Por padrão, a função <function>microtime</function> retorna uma <type>string</type> no
|
|
formato "msec sec", onde <literal>sec</literal> é o número de segundos
|
|
desde a época Unix (1 de Janeiro de 1970, 00:00:00 GMT), e <literal>msec</literal>
|
|
mensura os microssegundos que se passaram desde <literal>sec</literal>
|
|
e também é expressa em segundos, na forma de fração decimal.
|
|
</para>
|
|
<para>
|
|
Se o parâmetro opcional <parameter>as_float</parameter> for definido para &true;,
|
|
a função <function>microtime</function> retorna um <type>float</type> que
|
|
representa a hora atual em segundos desde a época Unix com precisão
|
|
de microssegundos.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Cronometrando a execução do script</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$time_start = microtime(true);
|
|
|
|
// Espera um momento
|
|
usleep(10_000);
|
|
|
|
$time_end = microtime(true);
|
|
$time = $time_end - $time_start;
|
|
|
|
print "Nada foi feito em $time segundo(s).\n";
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example>
|
|
<title><function>microtime</function> e <literal>REQUEST_TIME_FLOAT</literal></title>
|
|
<programlisting role="php" annotations="non-interactive">
|
|
<![CDATA[
|
|
<?php
|
|
// Tempo de espera aleatório
|
|
usleep(random_int(10_000, 1_000_000));
|
|
|
|
// REQUEST_TIME_FLOAT está disponível no array superglobal $_SERVER.
|
|
// Ele contém o timestamp do início da requisição com precisão de microssegundos.
|
|
$time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
|
|
|
|
echo "Nada foi feito em $time segundo(s).\n";
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>time</function></member>
|
|
<member><function>hrtime</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
|
|
-->
|