When working with PHP, understanding the memory limit set for the scripts can be critical for ensuring smooth performance and avoiding unexpected memory-related errors. PHP's memory_limit
directive specifies the maximum amount of memory a script is allowed to allocate, and it can significantly impact the scalability and stability of the application. This tutorial explains how to get PHP memory limit value.
The ini_get
function in PHP is used to retrieve the value of a configuration option. By passing memory_limit
as a parameter, it fetches the value of the memory limit directive defined in the PHP configuration file (php.ini
).
<?php
$memoryLimit = ini_get('memory_limit');
echo $memoryLimit;
If the memory_limit
is set to 128M
in the php.ini
file, the output of the script will be:
128M
If the code returns -1, it indicates that there is no memory limit.
Leave a Comment
Cancel reply