Press "Enter" to skip to content

Get information about your memory and CPU usage in PHP


In this tutorial, I am going to share how you can get information about your memory and CPU usage in PHP, optimizing server memory is a big problem and you may have to face server downtime issue.

PHP has a garbage collector and a pretty complex memory manager. The amount of memory being used by your script. can go up and down during the execution of a script.To get the current memory usage, we can use the memory_get_usage() function, and to get the highest amount of memory used at any point, we can use the memory_get_peak_usage() function.


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++) {
echo "Final Memory : ".memory_get_usage()." bytes \n";
//Final Memory :: 871015 bytes

echo "Peak: ".memory_get_peak_usage()." bytes \n";
//Peak: 13483071 bytes


CPU Usage Information

For getting CPU uses you can simply use getrusage() function in php It’ll return lot’s of CPU uses variables which help you to determine whats sources uses too much CPU resources.

How to POST and GET JSON Data using PHP cURL
How to Display Full Screen Image background using CSS
  1. Henrietta Sims Henrietta Sims


    I wanted to order a item from your webshop.
    but I can not find the product anymore on your site,
    it looks like this on this site
    I hope you will sell the product again soon,
    mail me if you are going to sell it again, I’ll wait


  2. Hey there! I’ve been reading your web site for a long time now and finally got the bravery to go ahead and give you a shout out from Lubbock Tx! Just wanted to mention keep up the excellent work!

  3. I was recommended this web site by my cousin. I am not
    sure whether this post is written by him as
    no one else know such detailed about my trouble. You’re wonderful!

Leave a Reply

Your email address will not be published. Required fields are marked *