mirror of
https://github.com/php/doc-es.git
synced 2026-03-25 16:02:13 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@335702 c90b9560-bf6c-de11-be94-00142212c4b1
157 lines
4.2 KiB
XML
157 lines
4.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: e41aab5ecacf449e51179886c17f1d41735b0234 Maintainer: seros Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
<refentry xml:id="function.microtime" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>microtime</refname>
|
|
<refpurpose>Devuelve la fecha Unix actual con microsegundos</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>mixed</type><methodname>microtime</methodname>
|
|
<methodparam choice="opt"><type>bool</type><parameter>get_as_float</parameter><initializer>false</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>microtime</function> devuelve la fecha Unix actual con
|
|
microsegundos. Esta función sólo está disponible en sistemas operativos que
|
|
soportan la llamada al sistema de gettimeofday().
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>get_as_float</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si se usa y se establece a &true;, <function>microtime</function> devolverá un
|
|
<type>float</type> en vez de un <type>string</type>, como está descrito en
|
|
la sección de valores de retorno de abajo.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Por omisión, <function>microtime</function> devuelve un <type>string</type> en
|
|
la forma "mseg seg", donde <literal>seg</literal> es el número de segundos
|
|
desde la época Unix (0:00:00 January 1, 1970 GMT), y <literal>msec</literal>
|
|
es el número de microsegundos que han transcurrido desde <literal>sec</literal>,
|
|
expresado en segundos.
|
|
</para>
|
|
<para>
|
|
Si <parameter>get_as_float</parameter> está establecido a &true;,
|
|
<function>microtime</function> devuelve un <type>float</type>, que
|
|
representa el momento actual en segundos desde la época Unix con precisión al
|
|
microsegundo más cercano.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejecución de un script de cronometraje con <function>microtime</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
/**
|
|
* Función sencilla para repetir el comportamiento de PHP 5
|
|
*/
|
|
function microtime_float()
|
|
{
|
|
list($usec, $sec) = explode(" ", microtime());
|
|
return ((float)$usec + (float)$sec);
|
|
}
|
|
|
|
$time_start = microtime_float();
|
|
|
|
// Dormir por un momento
|
|
usleep(100);
|
|
|
|
$time_end = microtime_float();
|
|
$time = $time_end - $time_start;
|
|
|
|
echo "No se hizo nada en $time segundos\n";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example>
|
|
<title>Ejecución de un script de cronometraje en PHP 5</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$time_start = microtime(true);
|
|
|
|
// Dormir por un momento
|
|
usleep(100);
|
|
|
|
$time_end = microtime(true);
|
|
$time = $time_end - $time_start;
|
|
|
|
echo "No se hizo nada en $time segundos\n";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example>
|
|
<title><function>microtime</function> y <literal>REQUEST_TIME_FLOAT</literal> (desde PHP 5.4.0)</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Tiempo de espera aleatorio
|
|
usleep(mt_rand(100, 10000));
|
|
|
|
// A partir de PHP 5.4.0, REQUEST_TIME_FLOAT está disponible en el array superglobal $_SERVER
|
|
// Contiene la fecha Unix en la que se realizó la petición con precisión de milisegundos.
|
|
$time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
|
|
|
|
echo "No se hizo nada en $time segundos\n";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>time</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
|
|
-->
|