xyz91 Posted October 12, 2019 Share Posted October 12, 2019 (edited) 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 October 12, 2019 by xyz91 Quote Link to comment https://forums.phpfreaks.com/topic/309359-number-of-attempts-to-communicate-with-the-host-and-unanswered-time/ Share on other sites More sharing options...
gw1500se Posted October 12, 2019 Share Posted October 12, 2019 You need to start with your schema. You seem to have mentioned what it is so show it. Quote Link to comment https://forums.phpfreaks.com/topic/309359-number-of-attempts-to-communicate-with-the-host-and-unanswered-time/#findComment-1570537 Share on other sites More sharing options...
xyz91 Posted October 13, 2019 Author Share Posted October 13, 2019 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/309359-number-of-attempts-to-communicate-with-the-host-and-unanswered-time/#findComment-1570554 Share on other sites More sharing options...
gw1500se Posted October 13, 2019 Share Posted October 13, 2019 If you don't know your own schema then it is impossible to get anything to work. Quote Link to comment https://forums.phpfreaks.com/topic/309359-number-of-attempts-to-communicate-with-the-host-and-unanswered-time/#findComment-1570561 Share on other sites More sharing options...
Barand Posted October 13, 2019 Share Posted October 13, 2019 Start by turning on the error reporting function of PHP. There are at least 3 that I've spotted. Quote Link to comment https://forums.phpfreaks.com/topic/309359-number-of-attempts-to-communicate-with-the-host-and-unanswered-time/#findComment-1570566 Share on other sites More sharing options...
xyz91 Posted October 13, 2019 Author Share Posted October 13, 2019 I solved my problem. You can delete the topic. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/309359-number-of-attempts-to-communicate-with-the-host-and-unanswered-time/#findComment-1570583 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.