Jump to content

Ping server


genesizz257

Recommended Posts

ok hi im new to the forums and didn't really know where to put this, so il put it here if its in the wrong place then im sorry, anyways currently im working on a site that will ping a server and come back with the standard Online/Offline and the MS, i've already worked on that cod and its working, one thing im not sure about though is, if its possible to only ping the server once every 2minets or so, as currently every person who comes on the site or presses F5 will ping it,

 

i was thinking maybe somehow storing the MS ect in a database, and having the PHP read from the database and somehow every 3 minutes having it update?, but im not really sure how i would go about doing this, or even if its possible my, mySQL isn't great to say the best, il leave the PHP code below and see what you think,

 

sorry about the code being a bit messy  :shrug:

        <tr>
          <td class="SEBody1">
		<?php
		// Function to check response time
			error_reporting(0);
			function pingDomain($domain)
			{
				$starttime = microtime(true);
				$file      = fsockopen ($domain, 443, $errno, $errstr, 10);
				$stoptime  = microtime(true);
				$status    = 0;

				if (!$file) $status = -1;  // Site is down
				else {
					fclose($file);
					$status = ($stoptime - $starttime) * 1000;
					$status = floor($status);
					}
				return $status;
			}

			echo '<table>';
				$domainbase ="ipadress";
				$status = pingDomain($domainbase);
				if ($status != -1) echo "<img src='img/shard_status_online.png' width='18' height='18' alt='Online' /> Online ";
				else  echo "<img src='img/shard_status_offline.png' width='18' height='18' alt='Offline' />Offline";

				echo '</table>';
	 ?>	
	  </td>
          <td class="SEBody1">Login</td>
          <td class="SEBody1">PvP</td>
          <td class="SEBody1">
		<?php 
			if ($status !=-1) echo "$status ms";
			else echo "0 ms";
			?>
	 </td>
          <td class="SEBody1">English</td>
        </tr>


Link to comment
https://forums.phpfreaks.com/topic/236662-ping-server/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.