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)
Search
NJ Beach Checker
| July 2010 | ||||||
| S | M | T | W | T | F | S |
| 27 | 28 | 29 | 30 | 1 | 2 | 3 |
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| « last | next » |
| beach days: | 52/131 (39.69%) |
| perfect beach days: | 6/52 (11.54%) |
| bad beach days: | 79/131 (60.31%) |
| best beach streak: | 3 |
| worst beach streak: | 10 days |
| avg temp: | 78.77° |
| avg wind: | 12.65 mph |
| avg water temp: | 70.7° |
One Year Ago
Day: SundayType: very_good
Temp: 86°
Wind: 6 mph
Water: 74°
Wave Height: 2 ft.
