9

My Thrift service expects to receive a Long integer representing a timestamp in milliseconds, but coming from PHP, I know PHP thrift is supposed to automagically turn my PHP types into thrift types, but which PHP type does it expect for Long integers? I think my computer is 64-bit, but since I think that PHP integers' length is platform dependent, I don't really want to depend upon a platform-dependent length for my integers.

I am currently grabbing microtime() and multiplying by 1000, then converting to integer. Is this the "correct" way to work with PHP & thrift long ints?

4

2 回答 2

7

你说的对,

整数的大小取决于平台,尽管通常值约为 20 亿的最大值(即 32 位有符号)。64 位平台的最大值通常约为 9E18。PHP 不支持无符号整数。自 PHP 4.4.0 和 PHP 5.0.5 起,可以使用常量 PHP_INT_SIZE 确定整数大小,使用常量 PHP_INT_MAX 确定最大值。

http://www.php.net/manual/en/language.types.integer.php

如果使用microtime(),则无需将其除以 1000。它的浮点数,您可能需要将其乘以 1000。

您可以使用BC Math使用字符串类型将其计算为数字。我猜字符串可以与任何其他事物进行通信。

如果乘以 1000,您甚至不需要BCMath. microtime(true)只需从(或空格microtime)的字符串表示中删除逗号

于 2012-07-17T15:47:51.447 回答
1

也许你应该像 twitter 一样使用字符串类型的 id:https ://dev.twitter.com/docs/twitter-ids-json-and-snowflake

于 2012-07-14T14:17:11.207 回答