Fatal error: Allowed memory size, when using ip2long function
Question by user1941709
I am using the ip2Long function below,
function ip_range($start, $end) {
$start = ip2long($start);
$end = ip2long($end);
return array_map('long2ip', range($start, $end) );
}
$range_one = "86.188.249.48 ";
$range_two = "86.188.249.55";
print_r( ip_range($range_one, $range_two) );
But I get the following error:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to
allocate 32 bytes) in /home/site/public_html/path/checkrange.php on
line 6
Answer by Samuel Cook
$range_one
is not considered a valid IP. If you remove the space off the end then this works for me:
$range_one = "86.188.249.48";
To avoid this in the future, you should trim
your values:
$start = ip2long(trim($start));
$end = ip2long(trim($end));