Page request on localhost takes 20 seconds to open

Asked

Viewed 1,342 times

0

I’m trying to show database data in a table.

    <html lang="en">
<head>




   <title>Estoque</title>

<!-- Bootstrap core CSS -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap theme -->
<link href="bootstrap/css/bootstrap-theme.min.css" rel="stylesheet">
<script src="bootstrap/js/bootstrap.min.js" </script>
<script src="jquery-2.1.4.min.js"</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>


<div class="container">  
        <table>
            <tr><b>
                <td>Código Produto</td>
                <td>Descrição</td>
                <td>Preço</td>
                <td>Quantidade Estoque</td>
            </tr></b>


<?php
REQUIRE_ONCE "conexao.php";
$sql = "SELECT id, cod_produto, dsc_produto, preco_produto, qtd_estoque, qtd_limitador FROM estoque";
$result = mysqli_query($conexao, $sql);
    while ($row = mysqli_fetch_assoc($result)) 
        { 

?>


            <tr bgcolor="<?php echo $bg ?>">
                <td><?php echo $row[cod_produto] ?></td>
                <td><?php echo $row[dsc_produto] ?></td>
                <td><?php echo $row[preco_produto] ?></td>
                <td><?php echo $row[qtd_estoque] ?></td>
                <td><?php echo $row[qtd_limitador] ?></td>



                <td>
                    <form method="get" action="edit.php">
                        <button type="hidden" name="id" class="btn btn-default" value="<?php echo $row[id]?>"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> </button>
                    </form>
                    <form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>">
                    <button type="button" name="botaoDelete" class="btn btn-default" data-toggle="modal" value="<?php echo $row[id] ?>" data-target="#myModal"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
                    </form>
                </td>
                </tr>



    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog">
    <div class="modal-content">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title">Excluir produto</h4>
  </div>
  <div class="modal-body">
    <p>Você tem certeza que deseja excluir?</p>

  </div>
  <div class="modal-footer">
    <form method="POST">
    <button type="button" name="botaoConfirma" value="<?php echo $dlt ?>" class="btn btn-danger">Excluir</button>
    <button type="button" class="btn btnn-default" data-dismiss="modal">Fechar</button>
    </form>


<?php      
    if (isset($_POST["botaoDelete"])) {
    $dlt = $_POST["botaoDelete"];
        if (isset($_POST["botaoConfirma"])) {
            $cnf = $_POST["botaoConfirma"];
            $deleteSql = mysqli_query($conexao, "DELETE * FROM estoque WHERE id='".$cnf."'");
        }

}

}   
?> 

  </div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->


</tbody>
</div>
</body>

When I call in the navigator, it takes about 20 seconds to open. Anyone can help?

  • How many items returns this query to mysql?

  • review the connections with the database.

  • Just a hint, your <script src="bootstrap/js...> is not closing the ">" tag causing the next one to open...

  • Always set a record limit to show, for example, on the first page from 1 to 10, on the second from 10 to 20, for example. Be careful not to select entire lines, especially if it is a web application.

  • Connections with the database are ok and this query returns around 30 lines. In fact, it returns 20 and half of line 21. Should I make a pagination now at the beginning? I imagine that 30 lines is not so big as to take so long.

  • I’ve narrowed it down to 5 and it’s still taking about 20 seconds to load.

Show 1 more comment

1 answer

1

Are you using Windows? If you are, make sure your server is serving connections only via Ipv4. If you are, it’s possible this is your problem.

What is happening is that Windows by default directs the "localhost" address to the loopback via Ipv6 (address ::1). If your server is only serving Ipv4, the connection does not close and is waiting for the timeout (which in your case should be those 20s). When he gives the timeout then he tries the Ipv4 address (127.0.0.1), which completes the connection.

If this is your problem (and not something else in PHP), the solution is to configure your server to accept loopback connections via Ipv6 or configure your client to connect to the address 127.0.0.1 instead of localhost.

  • I already set it up (I had seen it in another post in the OS) and still the error persists, which leads me to another question. Even being a beginner, it is worth installing a Linux distribution and start learning there?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.