gettimeofday() 总是可以访问吗?

发布于 2024-11-29 05:21:57 字数 1007 浏览 2 评论 0原文

我尝试过 Google、php.net 和 php 邮件列表的档案,但找不到 我在寻找什么。也许这是显而易见的,或者也许没有人好奇 这...

多年来,我一直使用 microtime() 来获取当前时间,包括 微秒。然而,有人给我指出了手册中的一句话 页面:“此功能仅在支持的操作系统上可用 gettimeofday() 系统调用。”

PHP 的 gettimeofday() 表明了同样的情况:“这是一个 gettimeofday(2) 的接口。”

但是...什么样的系统没有此系统调用可用? 一些谷歌搜索提供了许多 C 程序员试图获得 gettimeofday() 在 Windows 上用 C 语言实现,因为它似乎没有 包括它。但是 PHP 的 microtime() 和 gettimeofday() 似乎工作正常 在 Windows 上很好(至少是我能到达的盒子)。另外,我就是不能 似乎在网络上的任何地方都能找到 PHP 代码,似乎可以检查 在调用 microtime() 或 gettimeofday() 之前存在, 肯定有很多 PHP 程序员在从事 Windows 盒子所以...

我应该忽略手册中的这句话并相信两者 功能始终可用?或者还有其他跨平台的方式 获取系统时间,包括微秒,而不使用 microtime() 还是 gettimeofday()?或者这两个功能将永远存在, 但如果没有 gettimeofday() 系统,就不要给我微秒 可以打电话吗?

编辑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."

也许这个稍微澄清了我的观点。

I've tried Google, php.net and the php mailinglist's archives, but I can't find
what I'm looking for. Maybe it's obvious, or maybe nobody wonders about
this...

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

And PHP's gettimeofday() suggests the same situation: "This is an
interface to gettimeofday(2)."

But... what kind of systems then don't have this system call available?
Some googling around provided lots of C programmers trying to get a
gettimeofday() implementation in C on Windows, since it doesn't seem to
include it. But PHP's microtime() and gettimeofday() seem to work just
fine on Windows (at least the boxes I could get to). Also, I just can't
seem to find PHP code anywhere on the web that seems to check the
existence of either microtime() or gettimeofday() before they call it,
and there have to be lots of PHP programmers out there working on
Windows boxes so...

Should I ignore the sentence in the manual and just trust that both
functions are always available? Or is there another cross-platform way
to get to the system time, including the microseconds, without using
microtime() or gettimeofday()? Or will both functions just always exist,
but just not give me microseconds if there is no gettimeofday() system
call 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."

Maybe this clarifies my point somewhat.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

入画浅相思 2024-12-06 05:21:57

根据 来源 PHP 有它自己的 Windows gettimeofday 实现。但没有其他可用的 gettimeofday 端口。因此除了基于 UNIX 的系统和 Windows 之外,任何其他操作系统都不能使用 microtime()

According to sources PHP has its own gettimeofday implementation for Windows. But there's no other ports of gettimeofday available. So except UNIX based systems and Windows, any other operating systems cannot use microtime()

℡寂寞咖啡 2024-12-06 05:21:57

我在 Windows 和 Linux 上进行了广泛的开发,并在这两个平台上运行了可运行的 PHP 应用程序。我从来没有意识到这个问题,这对我来说从来都不是问题。

如果你能到达的话,我会把它视为一座跨越的桥梁。可以花费大量的时间和精力来寻找在我看来不是问题的解决方案。我建议您忽略手册中的这句话,直到这实际上成为您的问题,而不是在它可能发生的情况下浪费资源。

既然你已经让我意识到这个问题,我将遵循我自己的建议并忘记它。

I have developed extensively on both windows and linux and have working PHP applications running on both platforms. I have never been aware of this issue and it has never been a problem for me.

I would regard this as a bridge to cross if you get to it. A lot of time and energy could go into finding a solution for what seems to me to be a non problem. I reccomend that you ignore the sentence in the manual until this actually becomes an issue for you rather than wasting resources on the off chance that it could happen.

Now that you have made me aware of this issue I will follow my own advice and forget about it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文