【问题标题】:PHP: Read 8 bytes of timestamp from file on 32bit platform using gmp libraryPHP:使用 gmp 库从 32 位平台上的文件中读取 8 个字节的时间戳
【发布时间】:2020-06-22 06:40:50
【问题描述】:

尝试以这种方式读取以纳秒(8 字节)为单位的时间戳:

$fp = fopen($binFile, 'rb');
...
fseek($fp, $current * $event_len, SEEK_CUR);

// Read 8 bytes of timestamp apart
$ts_lo = fread($fp, 4);
$ts_hi = fread($fp, 4);
$ts = $ts_hi.$ts_lo;
$gmp = gmp_import($ts);

echo gmp_strval($gmp);

fclose($fp);

但是得到了错误的结果(比较 epochconverter.com 服务)。我怎样才能正确读取这 8 个字节?我的系统是 32bit little endian (linux arm)

【问题讨论】:

    标签: php file timestamp gmp


    【解决方案1】:

    回答我自己:

    gmp_strval (gmp_add (gmp_mul ($ts_hi, "4294967296"), $ts_lo)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-10
      • 2014-12-16
      • 2014-04-09
      相关资源
      最近更新 更多