Get information about your memory and CPU usage in PHP

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.

Code

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

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 upload excel file in PHP using CodeIgniter.

Some of the best Php Projects you can check

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

34 thoughts on “Get information about your memory and CPU usage in PHP”

  1. Hello

    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 https://bit.ly/ProductItem263
    I hope you will sell the product again soon,
    mail me if you are going to sell it again, I’ll wait

    Greetings

  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!
    Thanks!

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

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

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

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

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

  9. 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.
    Thanks

  10. 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
    work!

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

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

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

  14. 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?

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

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

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

  18. 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 😉

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

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

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

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

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

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

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

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

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

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

    Take care!!

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

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

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

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