mirror of
https://github.com/php/doc-pl.git
synced 2026-03-24 15:12:16 +01:00
132 lines
3.9 KiB
XML
Executable File
132 lines
3.9 KiB
XML
Executable File
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 3a8c3e77df070a046c9d5b56b68926ca2d7e5ee3 Maintainer: sobak Status: ready -->
|
|
<!-- $Revision$ -->
|
|
<!-- CREDITS: qrak -->
|
|
<refentry xml:id="function.microtime" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>microtime</refname>
|
|
<refpurpose>Zwraca aktualny uniksowy znacznik czasu z mikrosekundami</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>
|
|
<function>microtime</function> zwraca aktualny znacznik czasu Uniksa z
|
|
mikrosekundami. Ta funkcja jest dostępna tylko na systemach, które
|
|
umożliwiają wywołanie systemowe gettimeofday().
|
|
</para>
|
|
<para>
|
|
Do mierzenia wydajności rekomendowane jest użycie <function>hrtime</function>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>as_float</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Jeżeli użyto i ustawiono na &true;, <function>microtime</function> zwróci
|
|
liczbę zmiennoprzecinkową (<type>float</type>) zamiast łańcucha znaków (<type>string</type>),
|
|
jak opisano w sekcji "Zwracane wartości" poniżej.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Domyślnie <function>microtime</function> zwraca <type>string</type> w
|
|
w postaci "msek sek", gdzie <literal>sek</literal> to liczba sekund, które
|
|
upłynęły od epoki Uniksa (1 stycznia 1970 00:00:00 GMT), a <literal>msek</literal>,
|
|
to liczba sekund, które upłynęły od <literal>sek</literal>,
|
|
która także wyrażona jest w sekundach jako ułamek dziesiętny.
|
|
</para>
|
|
<para>
|
|
Jeżeli <parameter>as_float</parameter> ustawiono na &true;, to
|
|
<function>microtime</function> zwraca <type>float</type>, który
|
|
reprezentuje obecny czas w sekundach do epoki Uniksa, z dokładnością
|
|
do najbliższej mikrosekundy.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Mierzenie czasu pracy skryptu</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$czas_start = microtime(true);
|
|
|
|
// Poczekaj chwilę
|
|
usleep(10_000);
|
|
|
|
$czas_koniec = microtime(true);
|
|
$czas = $czas_koniec - $czas_start;
|
|
|
|
print "Nie robiłem nic przez $czas sekund\n";
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example>
|
|
<title><function>microtime</function> i <literal>REQUEST_TIME_FLOAT</literal> (od PHP 5.4.0)</title>
|
|
<programlisting role="php" annotations="non-interactive">
|
|
<![CDATA[
|
|
<?php
|
|
// Losowy czas uśpienia skryptu
|
|
usleep(random_int(10_000, 1_000_000));
|
|
|
|
// W tablicy superglobalnej $_SERVER dostępny jest klucz REQUEST_TIME_FLOAT.
|
|
// Zawiera on znacznik czasu w momencie rozpoczęcia żądania, z precyzją do mikrosekund.
|
|
$czas = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
|
|
|
|
echo "Nie robiłem nic przez $czas sekund\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
|
|
-->
|