Posted by brant : 2009-09-22 at 1:31 pm
There are times when you may want to get the load averages for your server in your PHP script. The reason of course is to prevent a script from running when the server is already taxed. I saw this PHP function to grab load averages at stackoverflow.com in the comments and thought it deserved more attention.
Below you will find an easy to use function, which returns 3 variables I aptly named one two and three. I have only used this on a linux box, but it should work on windows as well.
list($one,$two,$three) = get_server_load();
// $one = Past minute , $two = 5 minutes, $three = 15 minutes
function get_server_load($windows = 0) {
$os = strtolower(PHP_OS);
if(strpos($os, "win") === false) {
if(file_exists("/proc/loadavg")) {
$load = file_get_contents("/proc/loadavg");
$load = explode(' ', $load);
return $load;
}
elseif(function_exists("shell_exec")) {
$load = explode(' ', `uptime`);
return $load;
}
else {
return "";
}
}
}
Similar Blogs:
The Sad Truth About SEOBook
Cancel Your FreeCreditReport.com Account Without Calling
Automate Wordpress Posting
MySQL, How To SUM Time Correctly
blog comments powered by Disqus
Blog Posts
- The Sad Truth About SEOBook
- Firefox Had Its Chance, It's Time For Google Chrome
- Cancel Your FreeCreditReport.com Account Without Calling
- Automate Wordpress Posting
- MySQL, How To SUM Time Correctly
« Previous
Recent Popular Posts
Most Commented Blog Posts
- Nintendo Wii Sucks (228)
- Microsoft Windows Search Indexer Stopped Working (32)
- GMX Mail Review (31)
- Windows Vista And Windows 7 0x80070017 Error (16)
- How To Block Ad-Brite Transition Ads (14)
