Skip to content

[zend_]hrtime() returns constant value if unavailable or on error #19210

@marc-mabe

Description

@marc-mabe

Description

Sorry, for not following the bug template as this is a theoretical bug I can't reproduce together with a structural issue.

zend_hrtime() returns a constant value of 0 in case it's unavailable or in case of error.

The problem is that the availability isn't checked (ftp and zend_gc) and additionally the error condition could be a valid value.
-> As a result the time measurements might be buggy.

Similar situation for hrtime().

In case of error it will report a zero value which is a valid result.
In case of unavailability it will return false but normally if a functionality is unavailable in PHP it drops the function instead of returning a constant falsy value.

I haven't found an RFC for this feature, just a small ML discussion and the PR.

I would like to use zend_hrtime() for time measurements where current gettimeofday() is used (like in openssl and others) but currently this could silently fail and break the logic.

As it's already in use without checking availability/error I wonder if PHP actually supports systems where this is not available and if an error can actually happen.

Either the constant return should be removed -> make it fail to compile if unavailable and fail hard on error
or the function should not be made unavailable and make it somehow possible to safely check the error condition.

WDYT?

PHP Version

PHP >= 7.3.0

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy