Here is a normal client side sending an AJAX request to the server, without using any libraries.
About The Database:
There is only 1 table in the DB having 2 columns and 2 rows.
The Storage Engine in InnoDB
NOTE: This is a test DB. I also have another DB having 4 tables with 5000-6000 records and 18 other tables with less than 500 records
client.php:
<html>
...
<body>
<button class="btn__">Send</button>
<script>
var btn = document.querySelector('.btn__');
btn.onclick = function()
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
// document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("POST", "server_files/server.php", true);
xmlhttp.send();
}
</script>
</body>
...
</html>
server.php (CASE #1): No connection query to the database
<?php
// $con = mysqli_connect("host","username","pass","test_db");
echo json_encode([
'success' => true
]);
exit();
(response takes ~59ms)
server.php (CASE #2): Connection query to the database
<?php
$con = mysqli_connect("host","username","pass","test_db");
echo json_encode([
'success' => true
]);
exit();
(response takes ~452ms; this shouldn't be happening and it didn't happened until a week ago)
Why is it taking a long time for the response if I include that line of connection to the database ?
EDIT: (just putting if it'll be helpful to understand better)
When I run SHOW PROCESSLIST;
when the client is sending the AJAX request, I see this,