Skip to content
Advertisement

checking memory_limit in PHP

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 “M” it’s not reading properly the value. How to fix this ?

JavaScript

Advertisement

Answer

Try to convert the value first (eg: 64M -> 64 * 1024 * 1024). After that, do comparison and print the result.

JavaScript

Please note that the above code is just an idea. Don’t forget to handle -1 (no memory limit), integer-only value (value in bytes), G (value in gigabytes), k/m/g (value in kilobytes, megabytes, gigabytes because shorthand is case-insensitive), etc.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement