一个关于 PHP 奇怪的 Bug - V2EX
KasonPasser
V2EX    PHP

一个关于 PHP 奇怪的 Bug

  •  
  •   KasonPasser Dec 4, 2017 3434 views
    This topic created in 3085 days ago, the information mentioned may be changed or developed.

    一个应用的开始时间减去应用结束时的时间,小数点有时居然变成了逗号。

    部分代码:

     $mtime = explode(' ', microtime()); $app_starttime = $mtime[1] + $mtime[0]; /// 程序主体的运行 $mtime = explode(' ', microtime()); $app_endtime = $mtime[1] + $mtime[0]; $use_time = $app_endtime-$app_starttime; fb($use_time, 'exec time'); if($use_time > 5){ Yf_Log::log($use_time, Yf_Log::ERROR,'slow_slow_log'); } else if($use_time > 1){ Yf_Log::log($use_time, Yf_Log::ERROR,'slow_log'); } else { Yf_Log::log($use_time, Yf_Log::ERROR,'access_log'); } 

    记录的日志:

     Dec 04 13:21:47 FILE=/data/www/www.xxx.com/index.php [error] 0.03904914855957 {"ctl":"Index","met":"index","typ":"e"} #0 /data/www/www.xxx.com/index.php(211): Yf_Log::log(0.03904914855957,ERROR,access_log) Dec 04 13:21:48 FILE=/data/www/www.xxx.com/index.php [error] 0.11846590042114 {"firstRow":"12","totalRows":"123","ctl":"Goods_Goods","met":"goodslist","act":"all","cat_id":"268","actorder":"desc","typ":"e","keywords":""} #0 /data/www/www.xxx.com/index.php(211): Yf_Log::log(0.11846590042114,ERROR,access_log) dic 03 23:25:05 FILE=/data/www/www.xxx.com/index.php [error] 0,018435955047607 {"typ":"json","lang":"es_CR","ctl":"Buyer_Voucher","met":"getVoucherCount","__random":"0.6502593521184687"} #0 /data/www/www.xxx.com/index.php(211): Yf_Log::log(0,018435955047607,ERROR,access_log) dic 03 23:25:05 FILE=/data/www/www.xxx.com/index.php [error] 0,035964965820312 {"typ":"json","lang":"es_CR","ctl":"Buyer_Index","met":"getAllCount","__random":"0.6859251245657769"} 
    8 replies    2017-12-05 22:16:47 +08:00
    enenaaa
        1
    enenaaa  
       Dec 4, 2017
    microtime(true)
    或者
    $app_endtime = (float)$mtime[1] + (float)$mtime[0];

    看看。两个字符串相加可能出幺蛾子。
    picone
        2
    picone  
       Dec 4, 2017
    能看看格式化输出的地方?
    很是诡异,正常的日志日期是 Dec 04xxxx
    而不正常的日志日期是 dic 03xxxx
    有可能是分支结构后面格式化输出的地方打错了?
    KasonPasser
        3
    KasonPasser  
    OP
       Dec 4, 2017
    @enenaaa 添加了还是一样的。

    @picone 这个我也注意到了,dic 是西班牙 语的十二月。但是同一个的程序的逻辑也会出现这种结果。
    zgx030030
        4
    zgx030030  
       Dec 4, 2017
    搜索后得知西班牙语小数点为逗号,是不是你网站切多语言? 查查 setLocale 的使用?
    vex2
        5
    vex2  
       Dec 4, 2017
    确定一下是否有 runtime 的 ini 设置。 还有比如 php-fpm 启动的 worker 使用的配置是不是不一样的。
    huijiewei
        6
    huijiewei  
       Dec 4, 2017
    "lang":"es_CR"

    只要是逗号的里面的输出都有
    KasonPasser
        7
    KasonPasser  
    OP
       Dec 4, 2017
    @zgx030030
    @huijiewei 系统是有设置了多语言,但本地测试写死语言(西班牙语)也是正常的。
    mingyun
        8
    mingyun  
       Dec 5, 2017
    怪异,楼主找到问题了吗
    About     Help     Advertise     Blog     API     FAQ     Solana     1112 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 71ms UTC 23:49 PVG 07:49 LAX 16:49 JFK 19:49
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86