duanmuyao0463 2011-08-11 12:40
浏览 26
已采纳

gettimeofday()总是可以访问?

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.

  • 写回答

2条回答 默认 最新

  • duanjun7801 2011-08-12 13:41
    关注

    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()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥30 数字信号处理实验报告
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥15 ensp路由器启动不了一直报#
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了
  • ¥15 数学建模数学建模需要