PHP 扩展 - 获取当前时间毫秒

类似内置函数 microtime 中获取当前时间的毫秒数,下面实现参考了该函数的源代码:

// azalea.h
double getMicrotime();
// azalea.c
#include "ext/date/php_date.h"
#ifdef PHP_WIN32
#include "win32/time.h"
#elif defined(NETWARE)
#include 
#include 
#else
#include 
#endif
#define MICRO_IN_SEC 1000000.00

/* {{{ getMicrotime
 */
double getMicrotime()
{
    struct timeval tp = {0};
    if (gettimeofday(&tp, NULL)) {
        return 0;
    }
    return (double)(tp.tv_sec + tp.tv_usec / MICRO_IN_SEC);
}
/* }}} */

然后调用 getMicrotime 方法即可返回一个 double 类型的当前时间,可用于扩展内计算时间差。

你可能感兴趣的:(PHP 扩展 - 获取当前时间毫秒)