checking memory_limit in PHP

后端 未结 9 1528
臣服心动
臣服心动 2020-12-29 01:40

I\'m need to check if memory_limit is at least 64M in my script installer. This is just part of PHP code that should work, but probably due to this

9条回答
  •  执念已碎
    2020-12-29 02:18

    very old post. but i'll just leave this here:

    /* converts a number with byte unit (B / K / M / G) into an integer */
    function unitToInt($s)
    {
        return (int)preg_replace_callback('/(\-?\d+)(.?)/', function ($m) {
            return $m[1] * pow(1024, strpos('BKMG', $m[2]));
        }, strtoupper($s));
    }
    
    $mem_limit = unitToInt(ini_get('memory_limit'));
    

提交回复
热议问题