Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the CPU and Memory useage

I want to know the memory and CPU usage in php, because I'm using cronejobs sometimes the CPU is overloaded so in this case I don't wan to start more process, I just want to skip this cron.

like image 799
OHLÁLÁ Avatar asked Sep 24 '11 09:09

OHLÁLÁ


People also ask

Is CPU usage and memory usage same?

CPU time is used to process data. There is no relationship between CPU and memory usage. A process can occupy all CPUs of a system but use only a minimal amount of memory. Also, a process can allocate all memory available on a system but only use minimal CPU time.


2 Answers

I think better way is get load avarage, because it depends not only on CPU, but on HDD speed also.

Here is a doc: http://php.net/manual/en/function.sys-getloadavg.php

like image 183
neworld Avatar answered Sep 29 '22 12:09

neworld


Take a look at this library http://phpsysinfo.sourceforge.net/

Demo: http://phpsysinfo.sourceforge.net/phpsysinfo/index.php?disp=dynamic

Edit: This was taken from Stephen's comment. I put it here just so that it gets enough exposure for people to read.

Just a note: this library isn't too snappy. I couldn't find a way to just return CPU or just ram, it returns EVERYTHING, hardware list, network stats, hd usage, os info, pretty much everything you can think of. This takes it about 4 seconds to complete so it may not be the best option if you want a constantly updating value using ajax or something of the sort.

like image 34
Kemal Fadillah Avatar answered Sep 29 '22 11:09

Kemal Fadillah