Friday, 30 June 2017

How to get information about your memory and CPU usage in PHP.

How to get information about your memory and CPU usage in PHP.




See example.
echo "Initial Memory uses : ".memory_get_usage()." bytes \n";
// Initial Memory uses : 321420 bytes
 
// Let's create some function to use up some memory
for ($count = 0; $count < 100000; $count++) {
    $array []= base64_decode($count);
}
 
for ($count = 0; $count < 100000; $count++) {
    unset($array[$i]);
}
 echo "Final Memory : ".memory_get_usage()." bytes \n";
//Final Memory :: 871015 bytes
 
echo "Peak: ".memory_get_peak_usage()." bytes \n";
//Peak: 13483071 bytes

No comments:

Post a Comment