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 issues.

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 lots of CPU uses variables that help you to determine whats sources uses too much CPU resources.

Check out more useful tutorials:-

How to create Remember me function in PHP with CodeIgniter?

How to design Doraemon in Python?

Design a christmas tree using Python Turtle Package.

How to use JWT in CodeIgniter for creating API Authorization token.

How to POST and GET JSON Data using PHP cURL
How to Display Full Screen Image background using CSS
  1. Hi – I came across your website and I wanted to see if you have 3-5 minutes to see if I can reduce your payment processing fees? We have some awesome technology in place to help you earn more money. Please feel free to call or email me at 833.326.6729 opt.1 or [email protected]. Please feel free to check out our website at Thanks for your time!

  2. 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


  3. 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!

  4. There is apparently a lot to identify about this. I consider you made various good points in features also.

  5. 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!

  6. g g

    Hurrah! In the end I got a webpage from where I know how
    to actually obtain helpful facts regarding my study and knowledge.

  7. g g

    Hi there to all, the contents existing at this web page are actually remarkable
    for people knowledge, well, keep up the
    nice work fellows.

  8. g g

    Hi there, the whole thing is going sound here and ofcourse every one is sharing facts, that’s in fact
    good, keep up writing.

  9. g g

    Hello, i think that i saw you visited my website so i came to “return the
    favor”.I’m attempting to find things to improve my site!I suppose its ok
    to use some of your ideas!!

  10. Hello there! This post couldn’t be written any better!
    Reading this post reminds me of my old room mate!
    He always kept chatting about this. I will forward this article to him.
    Fairly certain he will have a good read. Many thanks for sharing!

  11. Malissa Malissa

    I do not know whether it’s just me or if everyone
    else experiencing problems with your blog. It appears as if some of the text
    on your content are running off the screen. Can somebody else please comment and let me know if this is
    happening to them too? This could be a problem with my internet browser because I’ve had this happen before.

  12. Orlando Orlando

    Hey there! I’m at work surfing around your blog from my new iphone!

    Just wanted to say I love reading your blog and look forward
    to all your posts! Carry on the outstanding

  13. Juliane Juliane

    Spot on with this write-up, I absolutely feel this site needs a
    great deal more attention. I’ll probably be returning to read through more,
    thanks for the info!


    Magnificent beat ! I wish to apprentice while you amend
    your site, how could i subscribe for a blog website?

    The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright clear concept

  15. Blair Blair

    You actually make it appear so easy along
    with your presentation however I to find this topic to be actually something that
    I believe I would never understand. It seems too complicated and very
    extensive for me. I am looking ahead to your next submit, I will try to
    get the cling of it!

  16. Dani Dani

    I’m curious to find out what blog system you happen to
    be working with? I’m having some minor security issues with my latest
    site and I’d like to find something more safe. Do you have any recommendations?

  17. Megan Megan

    Very rapidly this web site will be famous among
    all blogging and site-building visitors, due to it’s
    good articles or reviews

  18. Danial Danial

    After looking at a number of the blog posts on your
    website, I seriously appreciate your way of blogging.
    I book marked it to my bookmark website list and will be checking back soon. Please
    visit my web site too and tell me how you feel.

  19. Doris Doris

    I really like your blog.. very nice colors & theme. Did you create this website
    yourself or did you hire someone to do it for you? Plz answer
    back as I’m looking to design my own blog and would like to find out where u got this
    from. thank you

  20. Earlene Earlene

    I have to thank you for the efforts you have put in penning this blog.
    I am hoping to check out the same high-grade blog posts by you in the future as well.
    In truth, your creative writing abilities has motivated me to get my own, personal site now 😉

  21. Elaine Elaine

    This is really interesting, You’re a very skilled blogger.
    I’ve joined your feed and look forward to seeking more of your excellent post.
    Also, I have shared your website in my social networks!

  22. Jacqueline Jacqueline

    Fantastic beat ! I wish to apprentice while you amend your website, how can i subscribe
    for a blog site? The account helped me a acceptable
    deal. I had been tiny bit acquainted of this your broadcast offered bright clear concept

  23. Jacques Jacques

    This site definitely has all of the information I
    needed about this subject and didn’t know who to

  24. Brett Brett

    Sweet blog! I found it while browsing on Yahoo News. Do you have any suggestions on how to
    get listed in Yahoo News? I’ve been trying for a while but
    I never seem to get there! Many thanks

  25. Willy Willy

    Your method of telling the whole thing in this paragraph is in fact pleasant, all
    be able to simply be aware of it, Thanks a lot.

  26. Bennett Bennett

    That is a good tip particularly to those new to the blogosphere.
    Simple but very accurate information… Thank you for sharing this one.
    A must read post!

  27. Hortense Hortense

    I enjoy what you guys are up too. This kind of clever work and
    coverage! Keep up the great works guys I’ve incorporated you guys to my own blogroll.

  28. Jay Jay

    Hi there to every body, it’s my first pay a quick visit of this weblog; this website carries amazing and in fact good material designed for visitors.

  29. Homer Homer

    May I simply just say what a relief to discover an individual who truly
    knows what they are talking about on the internet. You certainly realize
    how to bring an issue to light and make it important.
    More and more people must check this out and understand
    this side of the story. I was surprised you aren’t more popular since you surely
    have the gift.

  30. Mary Mary

    Good blog you have here.. It’s difficult to find high quality writing like yours
    nowadays. I really appreciate people like you!

    Take care!!

  31. Virgilio Virgilio

    I am now not positive where you are getting your information, however good topic.

    I needs to spend some time studying more or understanding more.
    Thanks for excellent information I used to be in search of this information for my mission.

  32. Aleisha Aleisha

    Right away I am going away to do my breakfast, after having my breakfast coming
    again to read additional news.

  33. Drew Drew

    wonderful post, very informative. I ponder why the opposite specialists of this
    sector don’t notice this. You must continue your writing.
    I am confident, you have a great readers’ base already!

  34. Lourdes Lourdes

    Hello! Do you know if they make any plugins to assist with Search Engine Optimization? I’m trying to
    get my blog to rank for some targeted keywords but I’m not seeing very good results.
    If you know of any please share. Thanks!

Comments are closed.