php - functions outside of loop not updating -
i'm trying loop display few conditions based on load average , cpus/memory etc. however, seems pull usage info 1 time entire loop. want update on each loop: here's got, kind of help on great appreciated!
<?php exec("cat /proc/cpuinfo | grep processor | wc -l",$processors); $totalc=$processors[0]; function sys_getloadavg_hack() { $str = substr(strrchr(shell_exec("uptime"),":"),1); $avs = array_map("trim",explode(",",$str)); homecoming $avs; } $load = sys_getloadavg_hack(); function get_memory() { foreach(file('/proc/meminfo') $ri) $m[strtok($ri, ':')] = strtok(''); homecoming 100 - round(($m['memfree'] + $m['buffers'] + $m['cached']) / $m['memtotal'] * 100); } function print_exec(){ $out_arr=array(); $last_line=exec("mpstat",$out_arr); homecoming $last_line; } ($i=1; $i<=50; $i++) { $memory = get_memory(); $cpu = substr(print_exec(),-5); if($memory>"10" && $cpu>"10" && $load[0]<$totalc) { echo "everything good!"; } else { } echo "memory: $memory || cpu: $cpu || load avg: $load[0] || #cpu's: $totalc<br> || #runtime: $i\n\n"; usleep(800000); } ?>
you have create calculations every loop. example: phone call sys_getloadavg_hack() 1 time before loop.
try add together sys_getloadavg_hack() phone call in loop.
for(...) { $load = sys_getloadavg_hack(); ... }
php function loops while-loop
No comments:
Post a Comment