# phpman > perldoc > POE::Resource::Clock

## NAME
    [POE::Resource::Clock](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AResource%3A%3AClock/markdown) - internal clock used for ordering the queue

## SYNOPSIS
        sub [POE::Kernel::USE_POSIXRT](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AKernel%3A%3AUSEPOSIXRT/markdown) { 0 }
        use POE;

## DESCRIPTION
    [POE::Resource::Clock](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AResource%3A%3AClock/markdown) is a helper module for [POE::Kernel](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AKernel/markdown). It provides the features to keep an
    internal monotonic clock and a wall clock. It also converts between this monotonic clock and the
    wall clock.

    The monotonic clock is used to keep an ordered queue of events. The wall clock is used to
    communicate the time with user code ("alarm_set" in [POE::Kernel](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AKernel/markdown), "alarm_remove" in [POE::Kernel](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AKernel/markdown)).

    There are 3 possible clock sources in order of preference: [POSIX::RT::Clock](https://www.chedong.com/phpMan.php/perldoc/POSIX%3A%3ART%3A%3AClock/markdown), [Time::HiRes](https://www.chedong.com/phpMan.php/perldoc/Time%3A%3AHiRes/markdown) and
    "time" in perlfunc. Only "[POSIX::RT::Clock](https://www.chedong.com/phpMan.php/perldoc/POSIX%3A%3ART%3A%3AClock/markdown)" has a separate monotonic and wall clock; the other
    two use the same source for both clocks.

    Clock selection and behaviour is controlled with the following:

  USE_POSIXRT
        export POE_USE_POSIXRT=0
            or
        sub [POE::Kernel::USE_POSIXRT](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AKernel%3A%3AUSEPOSIXRT/markdown) { 0 }

    Uses the "monotonic" clock source for queue priority and the "realtime" clock source for wall
    clock. Not used if [POSIX::RT::Clock](https://www.chedong.com/phpMan.php/perldoc/POSIX%3A%3ART%3A%3AClock/markdown) is not installed or your system does not have a "monotonic"
    clock.

    Defaults to true. If you want the old POE behaviour, set this to 0.

  USE_STATIC_EPOCH
        export POE_USE_STATIC_EPOCH=0
            or
        sub [POE::Kernel::USE_STATIC_EPOCH](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AKernel%3A%3AUSESTATICEPOCH/markdown) { 0 }

    The epoch of the [POSIX::RT::Clock](https://www.chedong.com/phpMan.php/perldoc/POSIX%3A%3ART%3A%3AClock/markdown) monotonic is different from that of the realtime clock. For
    instance on Linux 2.6.18, the monotonic clock is the number of seconds since system boot. This
    epoch is used to convert from walltime into monotonic time for "alarm" in [POE::Kernel](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AKernel/markdown),
    "alarm_add" in [POE::Kernel](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AKernel/markdown) and "alarm_set" in [POE::Kernel](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AKernel/markdown). If "USE_STATIC_EPOCH" is true (the
    default), then the epoch is calculated at load time. If false, the epoch is calculated each time
    it is needed.

    Defaults to true. Only relevant for if using [POSIX::RT::Clock](https://www.chedong.com/phpMan.php/perldoc/POSIX%3A%3ART%3A%3AClock/markdown). Long-running POE servers should
    have this set to false so that system clock skew does mess up the queue.

    It is important to point out that without a static epoch, the ordering of the following two
    alarms is undefined.

        $poe_kernel->alarm_set( a1 => $time );
        $poe_kernel->alarm_set( a2 => $time );

  USE_EXACT_EPOCH
        export POE_USE_EXACT_EPOCH=1
            or
        sub [POE::Kernel::USE_EXACT_EPOCH](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AKernel%3A%3AUSEEXACTEPOCH/markdown) { 1 }

    There currently no way to exactly get the monotonic clock's epoch. Instead the difference
    between the current monotonic clock value to the realtime clock's value is used. This is
    obviously inexact because there is a slight delay between the 2 system calls. Setting
    USE_EXACT_EPOCH to true will calculate an average of this difference over 250 ms or at least 20
    samples. What's more, the system calls are done in both orders (monotonic then realtime,
    realtime then monotonic) to try and get a more exact value.

    Defaults to false. Only relevant if "USE_STATIC_EPOCH" is true.

  USE_HIRES
        export POE_USE_HIRES=0
            or
        sub [POE::Kernel::USE_HIRES](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AKernel%3A%3AUSEHIRES/markdown) { 0 }

    Use [Time::HiRes](https://www.chedong.com/phpMan.php/perldoc/Time%3A%3AHiRes/markdown) as both monotonic and wall clock source. This was POE's previous default clock.

    Defaults to true. Only relevant if "USE_POSIXRT" is false. Set this to false to use "time" in
    perlfunc.

## EXPORTS
    This module optionally exports a few timekeeping helper functions.

  mono2wall
### mono2wall

      my $wall = mono2wall( $monotonic );

  monotime
### monotime
    fall back to non-monotonic time if there are no monotonic clocks available.

      my $monotonic = monotime();

  sleep
### sleep
    monotonic clock. This feature will degrade gracefully to non-monotonic high-resolution clocks,
    then low-resolution clocks, depending on available libraries.

      sleep( 3.141 );

  time
### time
    details.

  wall2mono
### wall2mono
    time. Its feature degrades gracefully depending on clock availability.

      my $monotonic = wall2mono( $epoch );

  walltime
### time
    resolution known.

      my $epoch = walltime();

## SEE ALSO
    See [POE::Resource](https://www.chedong.com/phpMan.php/perldoc/POE%3A%3AResource/markdown) for general discussion about resources and the classes that manage them.

## BUGS
    None known.

AUTHORS & COPYRIGHTS
    Please see POE for more information about authors and contributors.

