checking memory_limit in PHP

后端 未结 9 1473
臣服心动
臣服心动 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:21

    Thank you for inspiration.

    I had the same problem and instead of just copy-pasting some function from the Internet, I wrote an open source tool for it. Feel free to use it or provide feedback!

    https://github.com/BrandEmbassy/php-memory

    Just install it using Composer and then you get the current PHP memory limit like this:

    $configuration = new \BrandEmbassy\Memory\MemoryConfiguration();
    $limitProvider = new \BrandEmbassy\Memory\MemoryLimitProvider($configuration);
    $limitInBytes = $memoryLimitProvider->getLimitInBytes();
    
    0 讨论(0)
  • 2020-12-29 02:28

    If you are interested in CLI memory limit:

    cat /etc/php/[7.0]/cli/php.ini | grep "memory_limit"
    

    FPM / "Normal"

    cat /etc/php/[7.0]/fpm/php.ini | grep "memory_limit"
    
    0 讨论(0)
  • 2020-12-29 02:29

    Command line to check ini:

    $ php -r "echo ini_get('memory_limit');"
    
    0 讨论(0)
提交回复
热议问题