Skip to content

Instantly share code, notes, and snippets.

@Aleksandr-ru
Last active January 11, 2022 16:24
Show Gist options
  • Save Aleksandr-ru/51316c7ccbd65af25960002296dea4eb to your computer and use it in GitHub Desktop.
Save Aleksandr-ru/51316c7ccbd65af25960002296dea4eb to your computer and use it in GitHub Desktop.
Get PHP memory limit in bytes
<?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