well managing memory is an important thing making good php scripts.
this little script will who you how many memory is your script using:
In the very beggining of you code (or the initial file, if you include more than a single file)
what this code does?
it creates a new variable ONLY if the php fuction memory_get_usage exists, if not $start_mem will be equal to zero.
and very ending of your script add this lines:
it will show something like this:
Memory Usage: 1.58 MB
if you are using a cms like phpnuke, maybe the best place to add the firt code is in the index.php file or the modules.php file.
and the second segment of code to the footer file, but dont forget add the $start_mem as global.
[code]global $start_mem;[/code
this code only works if php is compiled with the --enable--memory-limit option.
if your script is using a lot of memory, consider to use trough the script.
[code]unset($variable_name);[/code]
where $variable_name could be a number, a boolean, an array or just an string.
this little script will who you how many memory is your script using:
In the very beggining of you code (or the initial file, if you include more than a single file)
| Code: |
|
$start_mem = function_exists('memory_get_usage') ? memory_get_usage() : 0; |
what this code does?
it creates a new variable ONLY if the php fuction memory_get_usage exists, if not $start_mem will be equal to zero.
and very ending of your script add this lines:
| Code: |
|
if (function_exists('memory_get_usage') && $start_mem > 0) { $total_mem = memory_get_usage()-$start_mem; $memory_usage = '<br />Memory Usage: '.(($total_mem >= 1048576) ? round((round($total_mem / 1048576 * 100) / 100), 2).' MB' : (($total_mem >= 1024) ? round((round($total_mem / 1024 * 100) / 100), 2).' KB' : $total_mem.' Bytes')); } echo $memory_usage; |
it will show something like this:
Memory Usage: 1.58 MB
if you are using a cms like phpnuke, maybe the best place to add the firt code is in the index.php file or the modules.php file.
and the second segment of code to the footer file, but dont forget add the $start_mem as global.
[code]global $start_mem;[/code
this code only works if php is compiled with the --enable--memory-limit option.
if your script is using a lot of memory, consider to use trough the script.
[code]unset($variable_name);[/code]
where $variable_name could be a number, a boolean, an array or just an string.
