Author Topic: PHP problems on verification of server offline/online  (Read 13449 times)

Offline reaper

  • Opulent Member
  • *
  • Posts: 2872
  • Nice night for a walk, eh? - Nice night for a walk
    • View Profile
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #30 on: December 21, 2010, 04:19:06 PM »
 :rocketright:
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
VaeVictus "reaper is a lying sack of shit and ragequit then had, probably slugs, come alias and beat me, wasnt even the same person playing OBVIOUSLY, accuracies basicly doubled, and strategy

Offline console

  • Brobdingnagian Member
  • ***
  • Posts: 4518
  • "Man, this is the way to travel," said my attorney
    • View Profile
    • tastyspleen.net
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #31 on: December 21, 2010, 05:20:40 PM »
I researched the Q2 server ping/ack sequence.  I've made corrections to the following example code:

Quote from: php
<?php
$fp = fsockopen("udp://74.54.186.226", 27910, $errno, $errstr);
if (!$fp) {
    echo "ERROR: $errno - $errstr<br />\n";
} else {
    fwrite($fp, "\xFF\xFF\xFF\xFFping\x00");
    $coutput = fread($fp, 7);
    $cresponse = "\xFF\xFF\xFF\xFFack";

    if(strcmp($coutput,$cresponse) == 0){
        echo "server up";
    }
    else{
        echo "server down";
    }

    fclose($fp);
}
?>


Regards,

quadz

  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus

Offline Ace

  • Full Member
  • ***
  • Posts: 143
  • Band, the MMORPGDM
    • View Profile
    • ACE Intergraphs
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #32 on: December 21, 2010, 05:57:54 PM »
Thank you Quadz, and sorry for the major pain.... :(  I know how to code, just not the fundamentals yet with PHP...  like the characters * ! % ect.   all I know is $ is for variables
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
~~Ace~~

Offline reaper

  • Opulent Member
  • *
  • Posts: 2872
  • Nice night for a walk, eh? - Nice night for a walk
    • View Profile
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #33 on: December 21, 2010, 06:02:54 PM »
That's the same thing I wrote but a little nicer.  The \x hex is more human readable and it's not reading data it doesn't need to, it's recording exactly what it needs from the data stream and comparing the strings.

 :P
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
VaeVictus "reaper is a lying sack of shit and ragequit then had, probably slugs, come alias and beat me, wasnt even the same person playing OBVIOUSLY, accuracies basicly doubled, and strategy

Offline Ace

  • Full Member
  • ***
  • Posts: 143
  • Band, the MMORPGDM
    • View Profile
    • ACE Intergraphs
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #34 on: December 21, 2010, 06:36:35 PM »
I FIXED IT, and 75% of my trouble was not the PHP but the DNS on the server itself, here is the working code in its glory! http://www.aceintergraphs.com/

Quote
<?php
$serv1 = fsockopen("udp://www.aceintergraphs.com", 27910, $errno, $errstr);
$serv2 = fsockopen("udp://www.aceintergraphs.com", 27911, $errno, $errstr);
$serv3 = fsockopen("udp://www.aceintergraphs.com", 27912, $errno, $errstr);
$serv4 = fsockopen("udp://www.aceintergraphs.com", 27913, $errno, $errstr);
$serv5 = fsockopen("udp://www.aceintergraphs.com", 27914, $errno, $errstr);
$serv6 = fsockopen("udp://www.aceintergraphs.com", 27915, $errno, $errstr);
$serv7 = fsockopen("udp://www.aceintergraphs.com", 27916, $errno, $errstr);
$serv8 = fsockopen("udp://www.aceintergraphs.com", 27917, $errno, $errstr);
$serv9 = fsockopen("udp://www.aceintergraphs.com", 27918, $errno, $errstr);
$serv10 = fsockopen("udp://www.aceintergraphs.com", 27919, $errno, $errstr);
$serv11 = fsockopen("udp://www.aceintergraphs.com", 27920, $errno, $errstr);
$serv12 = fsockopen("udp://www.aceintergraphs.com", 27921, $errno, $errstr);

if ($serv1){
   fwrite($serv1, "\xFF\xFF\xFF\xFFping\x00");
   $soutput = fread($serv1, 7);
   $sresponse = "\xFF\xFF\xFF\xFFack";
   if(strcmp($soutput,$sresponse) == 0){
      echo '<br>Fezonia';
      echo '<img src="images/sonline.gif" width="100" height="8" alt="The Fezonia Realm is Online">';
   }else{
      echo '<br>Fezonia';
      echo '<img src="images/soffline.gif" width="100" height="8" alt="The Fezonia Realm is Offline">';
   }
fclose($serv1);
}

if ($serv2){
   fwrite($serv2, "\xFF\xFF\xFF\xFFping\x00");
   $soutput = fread($serv2, 7);
   $sresponse = "\xFF\xFF\xFF\xFFack";
   if(strcmp($soutput,$sresponse) == 0){
      echo '<br>Feasa';
      echo '<img src="images/sonline.gif" width="100" height="8" alt="The Feasa Realm is Online">';
   }else{
      echo '<br>Feasa';
      echo '<img src="images/soffline.gif" width="100" height="8" alt="The Feasa Realm is Offline">';
   }
fclose($serv2);
}

if ($serv3){
   fwrite($serv3, "\xFF\xFF\xFF\xFFping\x00");
   $soutput = fread($serv3, 7);
   $sresponse = "\xFF\xFF\xFF\xFFack";
   if(strcmp($soutput,$sresponse) == 0){
      echo '<br>Harlband';
      echo '<img src="images/sonline.gif" width="100" height="8" alt="The Harlband Realm is Online">';
   }else{
      echo '<br>Harlband';
      echo '<img src="images/soffline.gif" width="100" height="8" alt="The Harlband Realm is Offline">';
   }
fclose($serv3);
}

if ($serv4){
   fwrite($serv4, "\xFF\xFF\xFF\xFFping\x00");
   $soutput = fread($serv4, 7);
   $sresponse = "\xFF\xFF\xFF\xFFack";
   if(strcmp($soutput,$sresponse) == 0){
      echo '<br>Sodoara';
      echo '<img src="images/sonline.gif" width="100" height="8" alt="The Sodoara Realm is Online">';
   }else{
      echo '<br>Sodoara';
      echo '<img src="images/soffline.gif" width="100" height="8" alt="The Sodoara Realm is Offline">';
   }
fclose($serv4);
}

if ($serv5){
   fwrite($serv5, "\xFF\xFF\xFF\xFFping\x00");
   $soutput = fread($serv5, 7);
   $sresponse = "\xFF\xFF\xFF\xFFack";
   if(strcmp($soutput,$sresponse) == 0){
      echo '<br>Binndroa';
      echo '<img src="images/sonline.gif" width="100" height="8" alt="The Binndroa Realm is Online">';
   }else{
      echo '<br>Binndroa';
      echo '<img src="images/soffline.gif" width="100" height="8" alt="The Binndroa Realm is Offline">';
   }
fclose($serv5);
}

if ($serv6){
   fwrite($serv6, "\xFF\xFF\xFF\xFFping\x00");
   $soutput = fread($serv6, 7);
   $sresponse = "\xFF\xFF\xFF\xFFack";
   if(strcmp($soutput,$sresponse) == 0){
      echo '<br>Elboria';
      echo '<img src="images/sonline.gif" width="100" height="8" alt="The Elboria Realm is Online">';
   }else{
      echo '<br>Elboria';
      echo '<img src="images/soffline.gif" width="100" height="8" alt="The Elboria Realm is Offline">';
   }
fclose($serv6);
}

if ($serv7){
   fwrite($serv7, "\xFF\xFF\xFF\xFFping\x00");
   $soutput = fread($serv7, 7);
   $sresponse = "\xFF\xFF\xFF\xFFack";
   if(strcmp($soutput,$sresponse) == 0){
      echo '<br>Eskaara';
      echo '<img src="images/sonline.gif" width="100" height="8" alt="The Eskaara Realm is Online">';
   }else{
      echo '<br>Eskaara';
      echo '<img src="images/soffline.gif" width="100" height="8" alt="The Eskaara Realm is Offline">';
   }
fclose($serv7);
}

if ($serv8){
   fwrite($serv8, "\xFF\xFF\xFF\xFFping\x00");
   $soutput = fread($serv8, 7);
   $sresponse = "\xFF\xFF\xFF\xFFack";
   if(strcmp($soutput,$sresponse) == 0){
      echo '<br>Eldorian';
      echo '<img src="images/sonline.gif" width="100" height="8" alt="The Eldorian Realm is Online">';
   }else{
      echo '<br>Eldorian';
      echo '<img src="images/soffline.gif" width="100" height="8" alt="The Eldorian Realm is Offline">';
   }
fclose($serv8);
}

if ($serv9){
   fwrite($serv9, "\xFF\xFF\xFF\xFFping\x00");
   $soutput = fread($serv9, 7);
   $sresponse = "\xFF\xFF\xFF\xFFack";
   if(strcmp($soutput,$sresponse) == 0){
      echo '<br>Shamka';
      echo '<img src="images/sonline.gif" width="100" height="8" alt="The Shamka Realm is Online">';   
   }else{
      echo '<br>Shamka';
      echo '<img src="images/soffline.gif" width="100" height="8" alt="The Shamka Realm is Offline">';
   }
fclose($serv9);
}

if ($serv10){
   fwrite($serv10, "\xFF\xFF\xFF\xFFping\x00");
   $soutput = fread($serv10, 7);
   $sresponse = "\xFF\xFF\xFF\xFFack";
   if(strcmp($soutput,$sresponse) == 0){
      echo '<br>Redaila';
      echo '<img src="images/sonline.gif" width="100" height="8" alt="The Redaila Realm is Online">';
   }else{
      echo '<br>Redaila';
      echo '<img src="images/soffline.gif" width="100" height="8" alt="The Redaila Realm is Offline">';
   }
fclose($serv10);
}

if ($serv11){
   fwrite($serv11, "\xFF\xFF\xFF\xFFping\x00");
   $soutput = fread($serv11, 7);
   $sresponse = "\xFF\xFF\xFF\xFFack";
   if(strcmp($soutput,$sresponse) == 0){
      echo '<br>Skara';
      echo '<img src="images/sonline.gif" width="100" height="8" alt="The Skara Realm is Online">';
   }else{
      echo '<br>Skara';
      echo '<img src="images/soffline.gif" width="100" height="8" alt="The Skara Realm is Offline">';
   }
fclose($serv11);
}

if ($serv12){
   fwrite($serv12, "\xFF\xFF\xFF\xFFping\x00");
   $soutput = fread($serv12, 7);
   $sresponse = "\xFF\xFF\xFF\xFFack";
   if(strcmp($soutput,$sresponse) == 0){
      echo '<br>Prison';
      echo '<img src="images/sonline.gif" width="100" height="8" alt="The Prison is Online">';
   }else{
      echo '<br>Prison';
      echo '<img src="images/soffline.gif" width="100" height="8" alt="The Prison is Offline">';
   }
fclose($serv12);
}
?>
« Last Edit: December 21, 2010, 06:40:45 PM by Ace »
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
~~Ace~~

Offline Ace

  • Full Member
  • ***
  • Posts: 143
  • Band, the MMORPGDM
    • View Profile
    • ACE Intergraphs
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #35 on: December 21, 2010, 06:43:06 PM »
Thank you reaper, and quadz for your patients with this dumbass... :)  :rocketright: :rocketleft:  :exqueezeme:  :exqueezeme:  :rockon:
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
~~Ace~~

Offline fdrjk

  • Brobdingnagian Member
  • ***
  • Posts: 4996
  • gotta be above it
    • View Profile
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #36 on: December 21, 2010, 06:52:09 PM »
Nice Site.

 :rockon:
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus

Offline reaper

  • Opulent Member
  • *
  • Posts: 2872
  • Nice night for a walk, eh? - Nice night for a walk
    • View Profile
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #37 on: December 21, 2010, 06:55:35 PM »
tomorrow I will send a test server bogus input where the server parses the data stream, like:ping\xAAAAAA...challenge\xAAAAAAA.  Then I will look for segmentation faults.

I'm sure since it's such a popular protocol basic fuzzing like that won't reveal anything, but you never know! Problem is my C and assembly is not up to snuff to exploit stuff : (.

Ace: no problem, good luck

 :P
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
VaeVictus "reaper is a lying sack of shit and ragequit then had, probably slugs, come alias and beat me, wasnt even the same person playing OBVIOUSLY, accuracies basicly doubled, and strategy

Offline Ace

  • Full Member
  • ***
  • Posts: 143
  • Band, the MMORPGDM
    • View Profile
    • ACE Intergraphs
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #38 on: December 21, 2010, 07:14:41 PM »
The whole fuss here, is I am only testing, and preping for BAND, I got to make sure the server status is readable by the website, and thanks for the comment MCS_FaderJok0, I appriciate good comments on the site...
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
~~Ace~~

Offline reaper

  • Opulent Member
  • *
  • Posts: 2872
  • Nice night for a walk, eh? - Nice night for a walk
    • View Profile
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #39 on: December 21, 2010, 08:44:17 PM »
A friend of mine cleaned up your code a little

Quote from: php

<?php
$servarr = array('Fezonia'=>27910,
                 'Feasa'=>27911,
                 'Harlband'=>27912,
                 'Sodoara'=>27913,
                 'Binndroa'=>27914,
                 'Elboria'=>27915,
                 'Eskaara'=>27916,
                 'Eldorian'=>27917,
                 'Shamka'=>27918,
                 'Redaila'=>27919,
                 'Skara'=>27920,
                 'Prison'=>27921
                 );
$pingtext="\xFF\xFF\xFF\xFFping\x00";
$acktext="\xFF\xFF\xFF\xFFack";
foreach ($servarr as $key=>$val) {
  $errno=0;
  $errstr='';
  $sock=fsockopen("udp://www.aceintergraphs.com",$val,$errno,$errstr);
  if ($errno || !$sock) {
    // an error.  log it, notice, whatever.  your choice.
    $online=false;
  } else {
    fwrite($sock,$pingtext);
    $resp=fread($sock,7);
    $online=(strcmp($resp,$acktext)==0);
    fclose($sock);
  }
  echo "<br>{$key}<img src=\"images/s",($online?"on":"off"),
       "line.gif\" width=\"100\" height=\"8\" alt=\"The {$key} Realm is ",
       ($online?"On":"Off"),"line\" />";
}

Nice and neat

 :welcome:
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
VaeVictus "reaper is a lying sack of shit and ragequit then had, probably slugs, come alias and beat me, wasnt even the same person playing OBVIOUSLY, accuracies basicly doubled, and strategy

Offline console

  • Brobdingnagian Member
  • ***
  • Posts: 4518
  • "Man, this is the way to travel," said my attorney
    • View Profile
    • tastyspleen.net
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #40 on: December 21, 2010, 10:06:50 PM »
A friend of mine cleaned up your code a little

I wholeheartedly applaud the DRYing and de-CAMPing of the code. :bravo:


However, it should be noted that the refactored code will be significantly slower than the original to obtain all its results.

The original sent out all the UDP requests in parallel, and thus only had to wait for the results as long as the single slowest reply took to arrive.

The new code waits for the reply from each server before sending the next request, so the delays are all additive.

For example, in the original version, if 11 of the 12 servers answered the ping in 80 msec, and the 12th answered in 100 msec, then the total time to obtain the results, roughly speaking, would be 100 msec.

In the new version, under those same conditions, the time to obtain the results would be (11 * 80 + 100) = 980 msec.


A DRY version of the code that performed the same as the original would need two loops.


Regards,

quadz

  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus

Offline Ace

  • Full Member
  • ***
  • Posts: 143
  • Band, the MMORPGDM
    • View Profile
    • ACE Intergraphs
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #41 on: December 21, 2010, 10:34:18 PM »
Good point Quadz, and thank reaper.... but I had to modify it just a tad, and as long as it loads in less than 1 second is fine by me, if it becomes a problem I can always tweak it.  Or revert to the old one, since I backed it up before using this new code.
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
~~Ace~~

Offline routinet

  • Newbie
  • *
  • Posts: 2
    • View Profile
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #42 on: December 21, 2010, 11:52:37 PM »
I rarely work with sockets, so I appreciate you entertaining my ignorance...

However, it should be noted that the refactored code will be significantly slower than the original to obtain all its results.

The original sent out all the UDP requests in parallel, and thus only had to wait for the results as long as the single slowest reply took to arrive.

Can you provide benchmarks for that assertion?  I understand fread()/fwrite() are supposed to function asynchronously, but those calls are mixed with necessarily synchronous code in both samples.  In the original code, all of the sockets would be opened asynchronously, but the writing to/reading from would happen in order of appearance, yes?  e.g., the second write does not begin until after the first response has been received.

In my tests, both ran with roughly equivalent times.  My tests only added stream_set_timeout() after fsockopen(), for my own sanity, setting the timeout to 1 second.  Which brings up a curiosity:

About the servers that do not return the ping...how does the original code bypass the default timeout of 60 seconds?  The actual page loads quickly, so either all servers are returning *something*, or the timeout is being set somewhere other than the sample provided...?  All of the offline servers triggered the timeout when I ran the code.
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus

Offline quadz

  • Loquaciously Multiloquent Member
  • ****
  • Posts: 5352
    • View Profile
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #43 on: December 22, 2010, 12:28:01 AM »
Can you provide benchmarks for that assertion?  I understand fread()/fwrite() are supposed to function asynchronously, but those calls are mixed with necessarily synchronous code in both samples.  In the original code, all of the sockets would be opened asynchronously, but the writing to/reading from would happen in order of appearance, yes?  e.g., the second write does not begin until after the first response has been received.

You're right.  Brain fart on my part; sorry for the noise.

I've dealt with parallelized server pings before - and it seems I was reliving a past experience. :-[

My claim was based on (incorrectly) picturing the original code as though the fwrite()'s were occuring up at the top alongside the fsockopen()'s.

But indeed, that was not the case, and the old code and new code are equivalently synchronous.

In my own implementations, I've typically sent upwards of 64 pings in parallel, modulo available local bandwidth.


About the servers that do not return the ping...how does the original code bypass the default timeout of 60 seconds?  The actual page loads quickly, so either all servers are returning *something*, or the timeout is being set somewhere other than the sample provided...?  All of the offline servers triggered the timeout when I ran the code.

A guess: If the orignal page is being hosted on the same system as the Q2 servers being pinged, perhaps the OS kernel is helping to shortcut the delay by providing an 'unreachable' response, resulting in an immediate EOF on the fread().

I've always implemented this using the BSD sockets API (send / recvfrom), with the UDP sockets placed in nonblocking mode via fcntl().  (Or ioctlsocket() on Windows.)


Regards,

quadz

  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus
"He knew all the tricks, dramatic irony, metaphor, bathos, puns, parody, litotes and... satire. He was vicious."

Offline routinet

  • Newbie
  • *
  • Posts: 2
    • View Profile
  • Rated:
Re: PHP problems on verification of server offline/online
« Reply #44 on: December 22, 2010, 03:10:35 AM »
You're right.  Brain fart on my part; sorry for the noise.

Good to know I was not just missing something smack in front of my face.  As I said, I don't deal with sockets much, so I'm not intimately familiar with their behavior.  That saves me the trouble of rewriting my rewrite.  :P 

A guess: If the orignal page is being hosted on the same system as the Q2 servers being pinged, perhaps the OS kernel is helping to shortcut the delay by providing an 'unreachable' response, resulting in an immediate EOF on the fread().

A good guess, and one I should have caught on to seeing as how the socket target is the same domain as the response.  (there's that "smack in front of my face" thing again...) 

 :rockon: :afro:
  • Insightful
    Informative
    Funny
    Nice Job / Good Work
    Rock On
    Flawless Logic
    Well-Reasoned Argument and/or Conclusion
    Demonstrates Exceptional Knowlege of the Game
    Appears Not to Comprehend Game Fundamentals
    Frag of the Week
    Frag Hall of Fame
    Jump of the Week
    Jump Hall of Fame
    Best Solution
    Wins The Internet
    Whoosh! You done missed the joke thar Cletus!
    Obvious Troll Is Obvious
    DO YOU EVEN LIFT?
    DEMO OR STFU
    Offtopic
    Flamebait
    Redundant
    Factually Challenged
    Preposterously Irrational Arguments
    Blindingly Obvious Logical Fallacies
    Absurd Misconstrual of Scientific Principles or Evidence
    Amazing Conspiracy Theory Bro
    Racist Ignoramus

 

El Box de Shoutamente

Last 10 Shouts:

Costigan_Q2

November 11, 2024, 06:41:06 AM
"Stay cozy folks.

Everything is gonna be fine."

There'll be no excuses for having TDS after January 20th, there'll be no excuses AT ALL!!!
 

|iR|Focalor

November 06, 2024, 03:28:50 AM
 

RailWolf

November 05, 2024, 03:13:44 PM
Nice :)

Tom Servo

November 04, 2024, 05:05:24 PM
The Joe Rogan Experience episode 223 that dropped a couple hours ago with Musk, they're talking about Quake lol.

Costigan_Q2

November 04, 2024, 03:37:55 PM
Stay cozy folks.

Everything is gonna be fine.
 

|iR|Focalor

October 31, 2024, 08:56:37 PM

Costigan_Q2

October 17, 2024, 06:31:53 PM
Not activated your account yet?

Activate it now! join in the fun!

Tom Servo

October 11, 2024, 03:35:36 PM
HAHAHAHAHAHA
 

|iR|Focalor

October 10, 2024, 12:19:41 PM
I don't worship the devil. Jesus is Lord, friend. He died for your sins. He will forgive you if you just ask.
 

rikwad

October 09, 2024, 07:57:21 PM
Sorry, I couldn't resist my inner asshole.

Show 50 latest
Welcome, Guest. Please login or register.
November 23, 2024, 04:05:11 PM

Login with username, password and session length