gettimeofday

(PHP 4, PHP 5, PHP 7, PHP 8)

gettimeofdayObtém a hora atual

Descrição

gettimeofday ( bool $return_float = ? ) : mixed

Esta é uma interface para gettimeofday(2). Retorna um array contendo os dados retornado a chamada ao sistema.

Parâmetros

return_float

Quando definido como true, um float, ao invés de array, é retornado.

Valor Retornado

Por padrão, um array é retornado. Se o parâmetro return_float é definido, então um float é retornado.

Array keys:

  • "sec" - segundos desde a época Unix
  • "usec" - microsegundos
  • "minuteswest" - minutos a oeste de Greenwich
  • "dsttime" - tipo de correção dst

Changelog

Versão Descrição
5.1.0 O parâmetro return_float foi adicionado.

Exemplos

Exemplo #1 Exemplo da função gettimeofday()

<?php
 print_r
(gettimeofday());

 echo 
gettimeofday(true);
 
?>

O exemplo acima irá imprimir algo similar à:

 Array
 (
     [sec] => 1073504408
     [usec] => 238215
     [minuteswest] => 0
     [dsttime] => 1
 )

 1073504408.23910
 

add a note add a note

User Contributed Notes 2 notes

up
5
middleto at pilot dot msu dot edu
24 years ago
The types of DST correction (from sys/time.h on a Linux system):
0     Not on DST
1     USA DST
2     Austrailian DST
3     Western European DST
4     Middle European DST
5     Eastern European DST
6     Canada DST
7     Great Britain and Eire DST
8     Rumania DST
9     Turkey
10     Australian DST (with shift in 1986)
up
-2
lucas dot karisny at linuxmail dot org
19 years ago
A small improvement on getTimer.  Using vsprintf instead of sprintf there is no need to assign the array:

<?php
function utime()
{
  return (float) (
vsprintf('%d.%06d', gettimeofday()));
}
?>

In a test on my machine getTimer took 0.037519 seconds to run through 1000 iterations versus 0.027912 seconds for utime.  In total, utime runs about 25% quicker.  The use is negligible in an actual benchmarking scenario, but this could provide a slightly more accurate estimate.  Of course the time it takes to run the function could always be stored at the start and subtracted from your total value each time it is run.
To Top