I'm currently using the memory_get_usage
function to determine how much memory my PHP script is using. However, I want to display the memory usage value against the total amount of memory available to PHP.
How to I get the total amount of memory available to PHP?
You can use the php.ini setting memory_limit
:
ini_get('memory_limit');
Technically, this is not the total amount available to PHP, it's the amount available to a PHP script.
There is a problem that by using ini_get
you'll get just the string from php.ini
(e.g. 500
or 500M
or 1G
etc.).
Should you need the real value in bytes, you can use this simple open source tool: https://github.com/BrandEmbassy/php-memory
Then you can just do this: $limitProvider->getLimitInBytes();
and the library converts all valid values for you automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With