Running some major-traffic sites on shared hosting accounts is pretty tricky. I need to track the CPU use on a shared hosting account, so I know when to shut down the site as soon as it hits the limit. It is on cPanel if that makes any difference. Any ideas on how this can be accomplished would be good. Thanks
If you're on a Linux server you can try this (Taken from vBulletin): $servertoobusy = false; if ($vbulletin->options['loadlimit'] > 0 AND PHP_OS == 'Linux' AND @file_exists('/proc/loadavg') AND $filestuff = @file_get_contents('/proc/loadavg')) { $loadavg = explode(' ', $filestuff); if (trim($loadavg[0]) > $vbulletin->options['loadlimit']) { $servertoobusy = true; } } PHP: You can also give memory_get_usage() a try. EDIT: Perhaps you can find a cPanel log parser on hotscripts or Google.
Thanks. It looks like that vBulletin code only works with the option (loadlimit)? I'll try the log parser. I just got what I was afraid of : suspension for CPU usage
This loadlimit is just a variable. You'd have to replace $vbulletin->options['loadlimit'] with the actual value of the load limit that YOU want to set.
there is the vmstat command in linux. make use of it. I did a quick tweak for it to return cpu idle time (a percentage) at the time of checking. so command becomes: so if it returns 99, it means it is 99% percent idle, 1% busy so you can pass that to shell_exec() in a php script and echo the output, example: <? $idle = shell_exec("vmstat|awk {'print $15'}|tail -n 1"); $busy = 100-$idle; $busy .= "%"; echo "CPU is $busy busy"; ?> PHP: good luck PS: the number '15' above corresponds to the column titled 'cpu id'. it may vary. so execute vmstat at the prompt at first and get the count right
Assuming you don't own the server, there's no single way to track cpu usage. Certain shared host providers do try to track CPU usage, but that's own down to more server side code (which you can't access or manipulate) based on time consumption. Jay