I could not determine a good title for my problem but it is the following one, I am doing a small page to make queries to a database, the idea is that while the user writes in an input the results are shown in a table , for that I am implemented AJAX, a remote MySQL server and PHP, running the page from my PC runs very well, at the time of writing it looks for the data in the remote server and shows them at the moment, the problem is that I uploaded this page to a paid hosting and there at the time of writing, after doing a few queries is blocked and no longer looking for anything, I guess it has to be speed or something, but I can not find a way to optimize my code, I hope you can help me . I attached my page to do the tests: www.oaxaqueando.com just look for names of people and notice that it is blocked and no longer looking, the code I put it below:
function buscar_datos(consulta)
{
$.ajax({
url: 'buscar.php',
type: 'POST',
dataType: 'html',
data: {consulta: consulta},
})
.done(function(respuesta) {
$("#datos").html(respuesta);
})
}
$(document).on('keydown','#caja_busqueda',function(){
var valor = $(this).val();
buscar_datos(valor);
});
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<section>
<div class="form">
<input type="text" name="caja_busqueda" id="caja_busqueda">
</div>
<div id="datos">
</div>
</section>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="main.js"></script>
</body>
</html>
<?php
$buscar = str_replace(" ", "%", $_POST['consulta']);
$salida = "";
if ($buscar != "") {
$mysqli = new mysqli("servidor", "usuario", "contraseña", "bd");
mysqli_set_charset($mysqli, 'utf8');
$query = "SELECT * FROM bd_secjo.contactos where concat(nombres, ' ', apellido_paterno, ' ', apellido_materno) like '%" . $buscar . "%' limit 10;";
$resultado = $mysqli->query($query);
if ($resultado->num_rows > 0) {
$salida = "<table class='tabla_datos'>
<thead>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</thead>
<tbody>";
while($fila=$resultado->fetch_assoc()){
$salida = $salida . "<tr>" .
"<td>". $fila['Nombres'] . "</td>" .
"<td>". $fila['Apellido_Paterno'] . "</td>" .
"<td>". $fila['Apellido_Materno'] . "</td>" ;
}
$salida = $salida . "</tbody></table>";
} else {
$salida = "Sin resultados";
}
$mysqli->close();
}
echo $salida;
I use Windows 7, MySQL, Godaddy Hosting of 1 CPU, 512mb of RAM