Gather Linux Uptime (Multiple servers)
By: Daniel

In a response to a comment requesting information to get uptime of multiple servers, here is some sample code. This code can be expanded even more using a database to store website addresses, but for basic purposes I am just looping through an array of websites.

<?php
$sites = array('wlscripting.com'); // Create a list of sites to check
foreach($sites as $site) { // Loop through each site and get uptime

$ch = curl_init(); // Initiate curl session
curl_setopt($ch, CURLOPT_URL, 'http://'.$site.'/linuxUptime.php'); // Set the URL of the uptime script
curl_setopt($ch, CURLOPT_HEADER, 0); // Disable header output
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // Return data as a string instead of output directly
$data=curl_exec($ch); // Execute curl commands
curl_close ($ch); // Close the curl session

echo $site.': '.$data.'<br />'; // Output value returned from the linuxUptime.php file
} // End server loop
?>

This code loops through the $sites array to determine which sites to gather information from.
On every server you wish to check the uptime, create a file in the root of the domain called: linuxUptime.php. In this file you should include the code found in the Linux Uptime tutorial and only echo out the uptime. Anything that is output in the linuxUptime.php file will show up in the above output.

Enjoy!

 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 Votes | Average: 0 out of 5 (No Ratings Yet)
Loading ... Loading ...
del.icio.us:Gather Linux Uptime (Multiple servers) digg:Gather Linux Uptime (Multiple servers) spurl:Gather Linux Uptime (Multiple servers) wists:Gather Linux Uptime (Multiple servers) simpy:Gather Linux Uptime (Multiple servers) newsvine:Gather Linux Uptime (Multiple servers) blinklist:Gather Linux Uptime (Multiple servers) furl:Gather Linux Uptime (Multiple servers) reddit:Gather Linux Uptime (Multiple servers) fark:Gather Linux Uptime (Multiple servers) blogmarks:Gather Linux Uptime (Multiple servers) Y!:Gather Linux Uptime (Multiple servers) smarking:Gather Linux Uptime (Multiple servers) magnolia:Gather Linux Uptime (Multiple servers) segnalo:Gather Linux Uptime (Multiple servers)

Leave a Reply

eXTReMe Tracker
geovisitors