Last active
January 11, 2022 16:24
-
-
Save Aleksandr-ru/51316c7ccbd65af25960002296dea4eb to your computer and use it in GitHub Desktop.
Get PHP memory limit in bytes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getMemoryLimitBytes() | |
{ | |
$limit = ini_get('memory_limit'); | |
if ($limit == -1) return 0; | |
$units = [1 => 'K', 'M', 'G']; | |
$unit = strtoupper(substr($limit, -1)); | |
if ($exp = array_search($unit, $units)) { | |
return (int)substr($limit, 0, -1) * pow(1024, $exp); | |
} | |
else return (int)$limit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment