1
I have some servers I have to test if I have a connection.
Some of these servers have blocked access to my machine for testing, so they’ll give the message Can't connect to MySQL server on.
However, when they try to log into these servers that are blocked, they spend a lot of time trying to connect, so I tried to set up a Timeout following this link.
But it’s not working, I made the code as follows:
<?php
$link = mysqli_init();
if (!$link) {
die('mysqli_init failed');
}
if (!mysqli_options($link, MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {
die('Setting MYSQLI_INIT_COMMAND failed');
}
if (!mysqli_options($link, MYSQLI_OPT_CONNECT_TIMEOUT, 10)) {
die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
}
include("ConectCTOM.php");
$SELECT_SERVERS = "SELECT * FROM status_db";
$EXECUTE_SERVERS = mysqli_query($conexao, $SELECT_SERVERS);
?>
<br><br>
<?php
$i = 1;
while ($LINE_SERVERS = mysqli_fetch_array($EXECUTE_SERVERS)) {
$id = $LINE_SERVERS['id'];
$ips = $LINE_SERVERS['ip'];
$usuario = $LINE_SERVERS['user'];
$senha = $LINE_SERVERS['key'];
if (!$conecta = mysqli_real_connect($link, $ips, $usuario, $senha, 'bdcma')){
echo ('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
if($conecta){
$resultado = "Conectado ".$i;
} else {
$resultado = "Falhou ".$i;
}
echo '<a>'.$resultado.'</a><br>';
$i++;
}
mysqli_close($link);
?>
</body>
</html>