gpt4 book ai didi

用于节俭的 PHP 长整数

转载 作者:可可西里 更新时间:2023-11-01 12:17:26 25 4
gpt4 key购买 nike

我的 Thrift 服务期望接收一个代表毫秒时间戳的 Long 整数,但是来自 PHP,我知道 PHP thrift 应该自动将我的 PHP 类型转换为 thrift 类型,但是它期望哪种 PHP 类型用于 Long 整数?我认为我的计算机是 64 位的,但由于我认为 PHP 整数的长度是平台相关的,所以我真的不想依赖平台相关的整数长度。

我目前正在获取 microtime() 并乘以 1000,然后转换为整数。这是使用 PHP 和 thrift long int 的“正确”方式吗?

最佳答案

你是对的,

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

如果您使用 microtime(),则无需将其除以 1000。它是 float ,您可能需要将其乘以 1000。

您可以使用 BC Math使用字符串类型将其计算为数字。我想字符串可以与任何其他东西通信。

在乘以 1000 的情况下,您甚至不需要 BCMath。只需从 microtime(true) 的字符串表示中删除逗号(或从 microtime 中删除空格)

关于用于节俭的 PHP 长整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11434530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com