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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With