Jump to content

Number of attempts to communicate with the host and unanswered time


Recommended Posts

Hello, 

I have a problem with writing a function that will display the number of attempts to communicate with the host that have not been answered, if the host starts responding again, the table should display, for example 0. The website addresses are taken from the MySQL database. The next column should display the time from which the communication with the host was lost and if it responds, it should display, e.g. OK. Please, give me some hints how to write it. Thanks in advance.

Edited by xyz91

I do not know nothing working. Here code:

<?php 
$dbhost="localhost"; $dbuser="root"; $dbpassword="xxxxxx"; $dbname="database1";
$conn = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbname);
if (!$conn) {
echo "Error connection with MySQL" . PHP_EOL;
echo "Errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
$port = '80';
$result = mysqli_query($conn, "SELECT * FROM domens") or die ("Erro connection: $dbname");
print "<TABLE CELLPADDING=10 BORDER=1>";
print "<TR><TD>idt</TD><TD>Name</TD><TD>Working</TD><TD>Number of attempts</TD><TD>Time</TD></TR>\n";
while ($row = mysqli_fetch_array ($result)) {
$idt = $row[0];
$naame = $row[1];
$quantity = $row[2];
$time = $row[3];

$host = $name;
			
$numb_attemp = $quantity; 		
			$fp = @fsockopen($host, $port, $errno, $errstr, 30);

if($fp){
      print "<TR><TD>$idt</TD><TD>$name<TD>OK</TD><TD>0</TD><TD>$time</TD</TR>\n";
     $sql = "UPDATE addresses SET quantity = 0";
} else {
      print "<TR><TD>$idt</TD><TD>$nazwa<TD>OK</TD><TD>$numb_attemp</TD><TD>$time</TD</TR>\n";
       $sql = "UPDATE addresses SET quantity = quantity+1";
     }

 if (mysqli_query($conn, $sql)) {
     echo "sql update";
    }
    else {
        echo "sql no update";
    }

print "</TABLE>";
mysqli_close($conn);
?>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.