PHP的浮动错误:PHP挂起的数值 [英] PHP float bug: PHP Hangs On Numeric Value

查看:158
本文介绍了PHP的浮动错误:PHP挂起的数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚读了一篇关于php挂在某些浮点数的有趣文章,参见注册探索二进制

我从来没有明确地使用浮点数,我使用 number_format()来清理我的输入并显示例如价格。

另外,据我所知,例如形式的所有输入都是字符串,直到我告诉他们,否则我认为这个问题不会影响我。



我是对的,还是我需要检查我的服务器上的Wordpress和Squirrelmail安装示例,看看他们是否投入任何浮动?或者更好, grep 我的服务器上的所有php文件都是 float

$ b $ ol
  • 使用现代CPU。大多数现代的64位CPU将是免疫的(我实际上很难找到主机,因为他们倾向于使用更现代的硬件,允许重现它)。
  • 升级您的PHP版本 - 5.3.5和5.2.17一旦发布(可能是今天)就包含修复程序。

  • 在CFLAGS中使用 -ffloat-store 进行构建(会降低代码速度)。
  • 手动应用 patch 到您的代码并重新构建PHP。

    寻找具有 float 可能不会有帮助,因为引擎在许多字符串 - >数字转换场景中使用 zend_strtod

    这个代码btw是标准的BSD库 strtod 代码,不是PHP独有的。所以使用这个代码的其他项目也可能会受到影响。

    I just read an interesting article about php hanging on certain float numbers, see The Register and Exploring Binary.

    I never explicitly use floats, I use number_format() to clean my input and display for example prices.

    Also, as far as I am aware, all input from for example forms are strings until I tell them otherwise so I am supposing that this problem does not affect me.

    Am I right, or do I need to check for example Wordpress and Squirrelmail installations on my server to see if they cast anything to float? Or better, grep all php files on my servers for float?

    解决方案

    Ways to mitigate the problem:

    1. Use a modern CPU. Most modern 64-bit CPUs would be immune (I actually had trouble finding host that allows to reproduce it since they tend to use more modern hardware). Amazon VMs seem to be immune too.
    2. Upgrade your PHP version - 5.3.5 and 5.2.17 once released (probably today) include the fix.
    3. Build with -ffloat-store in CFLAGS (will slow down the code).
    4. Manually apply the patch to your code and rebuild PHP.

    Looking for the code that has float probably won't help as zend_strtod is used by the engine in many string->number conversion scenarios.

    P.S. this code btw is standard BSD library strtod code, not unique to PHP. So other projects using this code might be affected too.

    这篇关于PHP的浮动错误:PHP挂起的数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆