MrTechie
MrTechie

Reputation: 1847

determine memory used in php scripts

So I have a site that seems to be eating up some memory and I'd like to know if it's possible if there's a way for me to be able to detect how much memory gets used during the mysql calls. I was hoping there was a way that I could add a function and then call it at the start and end of the page and it would show me the memory used.

I need to try to cut down the memory being used in a few pages on this very old and outdated site. Yes I know, upgrade to some platform, but that's not really an option at the moment, so the next best thing is to figure out where it's eating up the memory.

I've poked at some articles but nothing really seems to go into depth and explain it well for me to grasp it. Any thoughts on how I could track down the memory leaks?

Upvotes: 0

Views: 122

Answers (2)

code_wrangler
code_wrangler

Reputation: 1669

Use show-profile, it works if you've mysql-5 running on your server.

http://dev.mysql.com/doc/refman/5.0/en/show-profile.html

It gives a detailed explanation of memory usage, processing time etc.

If you are only concerned about php then you can try using this

$startTime = microtime(true);
//Enter your query here
$endTime = microtime(true);
$totalTimeTaken = $endTime - $startTime;

hope this helps

Upvotes: 0

웃웃웃웃웃
웃웃웃웃웃

Reputation: 11984

Try with

echo memory_get_usage()

For checking the memory usage,.You can find more here

Upvotes: 2

Related Questions