Get CPU usage / RAM usage [PHP]
if you mean how much ram/cpu php is using then you can do the following using plain php without using any package: this returns the ram usage:
function get_server_memory_usage(){
$free = shell_exec('free');
$free = (string)trim($free);
$free_arr = explode("\n", $free);
$mem = explode(" ", $free_arr[1]);
$mem = array_filter($mem);
$mem = array_merge($mem);
$memory_usage = $mem[2]/$mem[1]*100;
return $memory_usage;
}
cpu usage:
function get_server_cpu_usage(){
$load = sys_getloadavg();
return $load[0];
}
Native Conditions:
$load = sys_getloadavg();
$limit =15; //percent cpu
if ($load[0] >= $limit) {
die("Oops Server Busy, this message was automate from Dimas Lanjaka For telling users, there too many processed.");
}
Comments
Post a Comment
Bila Ada posting yang kurang, atau error atau yang lainnya, silahkan tinggalkan komentar agar artikel/post di perbaiki.
Jangan Lupa Cek Box "Notify Me" agar tahu komentar kamu dibalas oleh saya.
If there are any posts that are missing, or error or anything else, please leave a comment for the article / post to be fixed.
Do not Forget Check Box "Notify Me" to know our comments replied by me.