Dynamic Uptime Updates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Denny
    Junior Member
    • Jun 2006
    • 12

    Dynamic Uptime Updates

    I wrote this little snippet the other day to get the current uptime stats of the server and display them on my site.

    Code:
    <?php 
     function get_include_contents($filename) {
           ob_start();
           include $filename;
           $contents = ob_get_contents();
           ob_end_clean();
           return $contents;
           }
      $alertralink = "http://uptime.alertra.com/uptime.php?id2=2174&id1=438912";
      $content = get_include_contents($alertalink);
      $beginuptime = '<td align=left><font face="Verdana" size=1 color="#000000"><b>';
      $enduptime = '%</b></font></td>';
      $startcut = strpos($content,$beginuptime)+62;
      $endcut = strpos($content,$enduptime);
      $uptimelength = $endcut - $startcut;
      $uptime = substr($content,$startcut,$uptimelength) . "%";
    ?>
    It retrieves the cumulative uptime only, and you'll need to update the Alertra link to your server's page.

    It works for cPanel36, I haven't checked out the Alertra pages for the other servers but I would assume they are the same or close. I'm also not sure if they ever change the coding on their pages, but for now this works great for me. To show the stats on your site, simply use:

    Code:
    <? echo $uptime; ?>
    Denny Cave
    Cave Interactive Media
    http://caveim.com
Working...