<?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 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.microtime.php',
    1 => 'microtime',
    2 => 'Restituisce l\'attuale UNIX timestamp con i microsecondi',
  ),
  'up' => 
  array (
    0 => 'ref.datetime.php',
    1 => 'Date/Time Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.localtime.php',
    1 => 'localtime',
  ),
  'next' => 
  array (
    0 => 'function.mktime.php',
    1 => 'mktime',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    '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"> Restituisce l&#039;attuale UNIX timestamp con i microsecondi</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.microtime-description">
  <h3 class="title">Descrizione</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">$get_as_float</code><span class="initializer"> = false</span></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>microtime()</strong></span> restituisce l&#039;attuale timestamp Unix in
   microsecondi. Questa funzione è disponibile solo su sistemi operativi che
   supportano la chiamata di sistema gettimeofday().
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.microtime-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">get_as_float</code></dt>
     <dd>
      <p class="para">
       Se utilizzato e impostato a <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, <span class="function"><strong>microtime()</strong></span> restituisce un
       <span class="type"><a href="language.types.float.php" class="type float">float</a></span> invece che un <span class="type"><a href="language.types.string.php" class="type string">string</a></span>, come descritto
       nella sezione sui valori di ritorno, più sotto.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.microtime-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Per default, <span class="function"><strong>microtime()</strong></span> restituisce una <span class="type"><a href="language.types.string.php" class="type string">string</a></span> in
   forma di &quot;msec sec&quot;, dove <code class="literal">sec</code> è il numero di secondi 
   dalla Unix Epoch (0:00:00 January 1, 1970 GMT), e <code class="literal">msec</code> 
   misura i microsecondi che sono trascorsi da <code class="literal">sec</code> 
   ed è ugualmente espresso in secondi.
  </p>
  <p class="para">
   Se <code class="parameter">get_as_float</code> è impostato a <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, allora
   <span class="function"><strong>microtime()</strong></span> restituisce un <span class="type"><a href="language.types.float.php" class="type float">float</a></span>, il quale
   rappresenta l&#039;orario attuale in microsecondi a partire dalla Unix epoch, approssimato al
   microsecondo più vicino.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.microtime-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Cronometrare l&#039;esecuzione di uno script con <span class="function"><strong>microtime()</strong></span></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/**<br /> * Semplice funzione che replica il comportamento di PHP 5<br /> */<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">microtime_float</span><span style="color: #007700">()<br />{<br />    list(</span><span style="color: #0000BB">$usec</span><span style="color: #007700">, </span><span style="color: #0000BB">$sec</span><span style="color: #007700">) = </span><span style="color: #0000BB">explode</span><span style="color: #007700">(</span><span style="color: #DD0000">" "</span><span style="color: #007700">, </span><span style="color: #0000BB">microtime</span><span style="color: #007700">());<br />    return ((float)</span><span style="color: #0000BB">$usec </span><span style="color: #007700">+ (float)</span><span style="color: #0000BB">$sec</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$time_start </span><span style="color: #007700">= </span><span style="color: #0000BB">microtime_float</span><span style="color: #007700">();<br /><br /></span><span style="color: #FF8000">// Sleep for a while<br /></span><span style="color: #0000BB">usleep</span><span style="color: #007700">(</span><span style="color: #0000BB">100</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_float</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 />echo </span><span style="color: #DD0000">"Non ho fatto nulla per </span><span style="color: #0000BB">$time</span><span style="color: #DD0000"> secondi\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
   <div class="example" id="example-2">
    <p><strong>Example #2 Cronometrare l&#039;esecuzione di uno script in PHP 5</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">// Sleep for a while<br /></span><span style="color: #0000BB">usleep</span><span style="color: #007700">(</span><span style="color: #0000BB">100</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 />echo </span><span style="color: #DD0000">"Non ho fatto nulla per </span><span style="color: #0000BB">$time</span><span style="color: #DD0000"> secondi\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
   <div class="example" id="example-3">
    <p><strong>Example #3 <span class="function"><strong>microtime()</strong></span> and <code class="literal">REQUEST_TIME_FLOAT</code> (as of PHP 5.4.0)</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Randomize sleeping time<br /></span><span style="color: #0000BB">usleep</span><span style="color: #007700">(</span><span style="color: #0000BB">mt_rand</span><span style="color: #007700">(</span><span style="color: #0000BB">100</span><span style="color: #007700">, </span><span style="color: #0000BB">10000</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// Da PHP 5.4.0, REQUEST_TIME_FLOAT è disponibile nell'array superglobale $_SERVER.<br />// Contiene il timestamp dell'inizio della richiesta con precisione al microsecondo.<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">"Non ho fatto nulla per </span><span style="color: #0000BB">$time</span><span style="color: #DD0000"> secondi\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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


 <div class="refsect1 seealso" id="refsect1-function.microtime-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.time.php" class="function" rel="rdfs-seeAlso">time()</a> - Restituisce l'attuale UNIX timestamp</span></li>
   </ul>
  </p>
 </div>

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