BetaArchive Logo
Total Current Archive Size: 4925.26GB in 15820 files
Navigation Home Screenshots Image Uploader Server Info FTP Servers Wiki Forum RSS Feed Rules Please Donate
UP: 6d, 5h, 14m | CPU: 30% | MEM: 4155MB of 12279MB used
{The community for beta collectors}

Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 PostPost subject: Short downtime this morning        Posted: Sun Aug 30, 2009 12:30 pm 
Site Administrator
Site Administrator
User avatar
Offline

Joined
Fri Aug 18, 2006 11:47 am

Posts
11467

Location
Merseyside, United Kingdom

Favourite OS
Microsoft Windows 7 Ultimate x64
Hello all,

There was a short downtime this morning of around 4 hours, when one of the crons failed to correctly run, causing the bandwidth stats to stop working. This caused a site-wide error causing each page load to take up to 5 minutes to complete. It only affected BetaArchive and none of the other websites hosted on the server.

Because of this error I have now implemented a fix. The fix checks to see if the stats are available before attempting to include the information into the script from the external http server the stats run from. If it was unavailable, it would cause a hang until the connection timed out. Now it waits no longer than 1 second before timing out, allowing the page to continue loading regardless.

Here is quick example of the fix code which may help anyone with a similar problem.
Code:
function isalive($port) {
  if (!is_numeric($port)) return false;
    $socket = @fsockopen("127.0.0.1:81", $port, $errno, $errstr, 1);
  if (!$socket)
     return false;
  else {
    fclose($socket);
    return true;
  }
  }

if (isalive(80)){ 
   $bandwidth = @file_get_contents("http://127.0.0.1:81/bandwidth.txt"));
} else{ echo(""); }


Andy (Admin)

_________________
Image


Top  Profile  WWW
 PostPost subject: Re: Short downtime this morning        Posted: Sun Aug 30, 2009 4:16 pm 
Pro Beta Collector
Pro Beta Collector
Offline

Joined
Mon Aug 17, 2009 10:23 am

Posts
473

Favourite OS
Dancing Banana
I was asleep till 2pm so no big problem for me :)

However may I suggest this shortened code. It only makes one request to 127.0.0.1 .. rather than testing then downloading.

Code:
ini_set('default_socket_timeout', '1');

$bandwidth = @file_get_contents('http://127.0.0.1:81/bandwidth.txt');

// do whatever with $bandwidth or nothing if it's empty


Top  Profile
 PostPost subject: Re: Short downtime this morning        Posted: Sun Aug 30, 2009 4:17 pm 
Site Administrator
Site Administrator
User avatar
Offline

Joined
Fri Aug 18, 2006 11:47 am

Posts
11467

Location
Merseyside, United Kingdom

Favourite OS
Microsoft Windows 7 Ultimate x64
I tried that, it doesn't work, or I'd use that method. I explored it in the past. Something to do with php itself ignoring the ini change. Don't ask, lol.

_________________
Image


Top  Profile  WWW
 PostPost subject: Re: Short downtime this morning        Posted: Sun Aug 30, 2009 4:31 pm 
Pro Beta Collector
Pro Beta Collector
Offline

Joined
Mon Aug 17, 2009 10:23 am

Posts
473

Favourite OS
Dancing Banana
Then the next best thing..

Code:
function get_bandwidth()
{
    $socket = @fsockopen("127.0.0.1", 81, $errno, $errstr, 1);

    if (!$socket) { return; }

    $headers  = "GET /bandwidth.txt HTTP/1.1\r\n";
    $headers .= "Host: 127.0.0.1\r\n";
    $headers .= "Connection: Close\r\n\r\n";

    $bandwidth = "";

    fwrite($socket, $headers);

    while (!feof($socket))
    {
        $bandwidth .= fgets($socket);
    }

    fclose($socket);

    // strip the http headers from the output
    $bandwidth = substr($bandwidth, (strpos($bandwidth, "\r\n\r\n") + 4));

    return $bandwidth;
}

$bandwidth = get_bandwidth();

// do whatever with $bandwidth or nothing if it's empty


Also I take it you are using port 81.. and the passing of port 80 on your first post is by mistake?


Top  Profile
 PostPost subject: Re: Short downtime this morning        Posted: Sun Aug 30, 2009 4:48 pm 
Site Administrator
Site Administrator
User avatar
Offline

Joined
Fri Aug 18, 2006 11:47 am

Posts
11467

Location
Merseyside, United Kingdom

Favourite OS
Microsoft Windows 7 Ultimate x64
Actually I'm using neither port. I changed the entire example to use fake information, since it was just an example. I'd also rather people didn't know the actual url :)

Anyway, the script uses your caching code, so it only requests it once every 5 seconds maximum anyway :)

_________________
Image


Top  Profile  WWW
 PostPost subject: Re: Short downtime this morning        Posted: Sun Aug 30, 2009 5:40 pm 
Pro Beta Collector
Pro Beta Collector
Offline

Joined
Mon Aug 17, 2009 10:23 am

Posts
473

Favourite OS
Dancing Banana
Still your example connects, disconnects the connects again to download :P


Top  Profile
 PostPost subject: Re: Short downtime this morning        Posted: Sun Aug 30, 2009 5:41 pm 
Site Administrator
Site Administrator
User avatar
Offline

Joined
Fri Aug 18, 2006 11:47 am

Posts
11467

Location
Merseyside, United Kingdom

Favourite OS
Microsoft Windows 7 Ultimate x64
monkey56657 wrote:
Still your example connects, disconnects the connects again to download :P

Very true, but either way once every 5 seconds is hardly going to do any damage.

_________________
Image


Top  Profile  WWW
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 




Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

All views expressed in these forums are those of the author and do not necessarily represent the views of the BetaArchive site owner.

Powered by phpBB® Forum Software © phpBB Group

Copyright © 2006-2013

 

Sitemap | XML | RSS