Is gettimeofday () always available?

I tried Google, php.net and php mailing list archives, but I can not find what I am looking for. Maybe this is obvious, or maybe no one wonders about this ...

For many years, I used microtime () to get the current time, including microseconds. However, someone pointed me to a suggestion in the page manual: "This function is only available on operating systems that support the gettimeofday () system call.

And PHP gettimeofday () offers the same situation: "This is the interface for gettimeofday (2)."

But ... which systems then do not have this system call? Some search engines offer many C programmers trying to get gettimeofday () in C on Windows since it doesn't seem to turn it on. But PHP microtime () and gettimeofday () seem to work just fine on Windows (at least boxes can get). Also, I just can't seem to find the PHP code anywhere on the Internet that seems to check for either microtime () or gettimeofday () before they call it, and there should be a lot of PHP programmers working there there are Windows Boxes, so ...

Should I ignore the suggestion in the manual and simply trust that both functions are always available? Or is there another cross-platform way to get system time, including microseconds, without using microtime () or gettimeofday ()? Or both functions will always exist, but just don’t give me microseconds if there is no gettimeofday () system a call is available?

EDIT 1:

http://www.php.net/microtime

"Returns the current Unix timestamp with microseconds. This function is only available on operating systems that support the gettimeofday() system call." 

Perhaps this clarifies my point a bit.

+6
source share
2 answers

I have been actively developing both on Windows and Linux, and I have working PHP applications running on both platforms. I never knew about this problem, and it was never a problem for me.

I would see it as a bridge to cross if . A lot of time and energy could find a solution to what seems like a problem to me. I recommend that you ignore the suggestion in the manual until it becomes a problem for you, and does not waste resources in case this happens.

Now that you have informed me of this, I will follow my advice and forget about it.

0
source

Source: https://habr.com/ru/post/894827/


All Articles