<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.datetime.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.microtime.php',
    1 => 'microtime',
    2 => 'Retourne le timestamp UNIX actuel avec les microsecondes',
  ),
  'up' => 
  array (
    0 => 'ref.datetime.php',
    1 => 'Fonctions Date/Heure',
  ),
  'prev' => 
  array (
    0 => 'function.localtime.php',
    1 => 'localtime',
  ),
  'next' => 
  array (
    0 => 'function.mktime.php',
    1 => 'mktime',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/datetime/functions/microtime.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.microtime" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">microtime</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">microtime</span> &mdash; <span class="dc-title">Retourne le timestamp UNIX actuel avec les microsecondes</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.microtime-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>microtime</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$as_float</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.float.php" class="type float">float</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>microtime()</strong></span> retourne le timestamp Unix, avec 
   les microsecondes. Cette fonction est uniquement disponible sur 
   les systèmes qui supportent la fonction gettimeofday().
  </p>
  <p class="para">
   Pour mesurer les performances, l&#039;utilisation de <span class="function"><a href="function.hrtime.php" class="function">hrtime()</a></span>
   est recommandée.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.microtime-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">as_float</code></dt>
     <dd>
      <p class="para">
       Si utilisé et défini à <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, <span class="function"><strong>microtime()</strong></span> retournera
       un nombre à virgule flottante au lieu d&#039;une <a href="language.types.string.php" class="link">chaîne de caractères</a>, tel que décrit
       dans la section des valeurs retournées ci-dessous.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.microtime-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Par défaut, <span class="function"><strong>microtime()</strong></span> retourne une <a href="language.types.string.php" class="link">chaîne de caractères</a> au
   format &quot;msec sec&quot;, où <code class="literal">sec</code> est le nombre de secondes
   depuis l&#039;époque Unix (1 Janvier 1970, 00:00:00 GMT),
   et <code class="literal">msec</code> est le nombre de microsecondes qui se sont écoulées
   depuis <code class="literal">sec</code>, exprimé en secondes sous forme de fraction 
   décimale.
  </p>
  <p class="para">
   Si <code class="parameter">as_float</code> est défini à <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, alors
   <span class="function"><strong>microtime()</strong></span> retourne un nombre à virgule flottante,
   qui représente le temps courant, en secondes, depuis l&#039;époque Unix, précis
   à la microseconde près.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.microtime-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Durée d&#039;exécution d&#039;un script en PHP</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$time_start </span><span style="color: #007700">= </span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Attend pendant un moment<br /></span><span style="color: #0000BB">usleep</span><span style="color: #007700">(</span><span style="color: #0000BB">10_000</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$time_end </span><span style="color: #007700">= </span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$time </span><span style="color: #007700">= </span><span style="color: #0000BB">$time_end </span><span style="color: #007700">- </span><span style="color: #0000BB">$time_start</span><span style="color: #007700">;<br /><br />print </span><span style="color: #DD0000">"Ne rien faire pendant </span><span style="color: #0000BB">$time</span><span style="color: #DD0000"> secondes\n"</span><span style="color: #007700">;</span></span></code></div>
    </div>

   </div>
   <div class="example" id="example-2">
    <p><strong>Exemple #2 Exemple avec <span class="function"><strong>microtime()</strong></span> et <code class="literal">REQUEST_TIME_FLOAT</code></strong></p>
    <div class="example-contents">
<div class="annotation-non-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Durée d'attente aléatoire<br /></span><span style="color: #0000BB">usleep</span><span style="color: #007700">(</span><span style="color: #0000BB">random_int</span><span style="color: #007700">(</span><span style="color: #0000BB">10_000</span><span style="color: #007700">, </span><span style="color: #0000BB">1_000_000</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// REQUEST_TIME_FLOAT est disponible dans le tableau superglobal $_SERVER.<br />// Il contient le timestamp du début de la requête, avec une précision à la microseconde.<br /></span><span style="color: #0000BB">$time </span><span style="color: #007700">= </span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">) - </span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">"REQUEST_TIME_FLOAT"</span><span style="color: #007700">];<br /><br />echo </span><span style="color: #DD0000">"Ne rien faire pendant </span><span style="color: #0000BB">$time</span><span style="color: #DD0000"> secondes\n"</span><span style="color: #007700">;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.microtime-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.time.php" class="function" rel="rdfs-seeAlso">time()</a> - Retourne l'horodatage UNIX actuel</span></li>
    <li><span class="function"><a href="function.hrtime.php" class="function" rel="rdfs-seeAlso">hrtime()</a> - Renvoie le temps de haute r&eacute;solution du syst&egrave;me</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>