简体   繁体   中英

PHP long integers for thrift

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?

You are right,

The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18. PHP does not support unsigned integers. Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5.

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

If you use microtime() you need not to divide it by 1000. Its float, you may want to multiply it by 1000.

You may use BC Math for calclulate it as numbers, using string types. I guess string are OK to communicate with any other thing.

In case of multiplying by 1000, you even not need BCMath . Just delete comma from string representation of microtime(true) (or space from microtime )

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM