suche nach in der

gmdate> <getdate
Last updated: Fri, 18 May 2012

view this page in

gettimeofday

(PHP 4, PHP 5)

gettimeofdayErmittelt die aktuelle Zeit

Beschreibung

mixed gettimeofday ([ bool $return_float = false ] )

Es handelt sich um eine Schnittstelle zum Systemaufruf von gettimeofday(2). Die Funktion gibt ein assoziatives Array zurück, das die Daten enthält, die der Systemaufruf produziert hat.

Parameter-Liste

return_float

Sofern auf TRUE gesetzt, wird eine Fließkommazahl anstelle des Arrays zurückgegeben.

Rückgabewerte

Standardmäßig wird ein Array zurückgegeben. Wenn der Parameter return_float angegeben wurde, ist der Rückgabewert vom Typ float.

Array-Schlüssel:

  • "sec" - Sekunden seit der Unix-Epoche
  • "usec" - Microsekunden
  • "minuteswest" - Minuten westlich von Greenwich
  • "dsttime" - Art der Korrektur der Sommerzeit

Changelog

Version Beschreibung
5.1.0 Der Parameter return_float wurde hinzugefügt.

Beispiele

Beispiel #1 gettimeofday()-Beispiel

<?php
print_r
(gettimeofday());

echo 
gettimeofday(true);
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

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

1073504408.23910



add a note add a note User Contributed Notes
gettimeofday
void0( the dog )yandex.ru
21-Sep-2006 08:07
do you realy think that convertion to String and back to float can be fast??
this function runs 10 times faster than utime() :

function fastUtime()
{
  $t = gettimeofday();
  return (float) ($t['sec'] + $t['usec'] / 1000000.0);
}
lucas dot karisny at linuxmail dot org
14-Feb-2005 03:26
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.
beidson at calpoly dot edu
14-Sep-2000 08:21
Since USLEEP doesn't work under windows, you need to come up with your own fix. gettimeofday() can access useconds on a windows box, so this little function using gettimeofday() will do the trick.

function wait($usecs){
 $temp=gettimeofday();
 $start=(int)$temp["usec"];
 while(1){
  $temp=gettimeofday();
  $stop=(int)$temp["usec"];
  if ($stop-$start >= $usecs) break;
 }
}

The smallest amount of time it seems to work with is around 200usecs, but if you wait() anything higher than 200usecs it's pretty close.
middleto at pilot dot msu dot edu
13-Aug-1999 04:49
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)

gmdate> <getdate
Last updated: Fri, 18 May 2012