PHP with MySQL is slow
It could be happening in a couple of places: 1) the query itself, or 2) the creation of the mysqli instance (and resulting db connection). If I had to guess, I suspect your problem is (2).
One quick-and-dirty debugging method is to use microtime()
.
http://www.php.net/manual/en/function.microtime.php
Example:
$start = microtime(TRUE); // Start counting
$mysqli = new mysqli('localhost', 'root', '', 'testdb');
$temp = microtime(TRUE) - $start;
echo "Time to connect: {$temp}"; // Check elapsed time
$mysqli->set_charset("utf8");
if(mysqli_connect_errno()) {
echo "Connection Failed: " . mysqli_connect_errno();
exit();
}
$temp = microtime(TRUE) - $start;
echo "Time to setup: {$temp}"; // Check elapsed time
$testreceive = $_POST['test_id'];
$query = "SELECT First_Name from tblperson";
$result = $mysqli->query($query);
$temp = microtime(TRUE) - $start;
echo "Time to query: {$temp}"; // Check elapsed time
$row = $result->fetch_all(MYSQLI_ASSOC);
$temp = microtime(TRUE) - $start;
echo "Time to fetch {$temp}"; // Check elapsed time
Add the following line in the hosts file located in ”C:\Windows\System32\drivers\etc”
127.0.0.1 localhost
This solved my problem. PHP-MySQL can now complete its task depending on how complex somewhere between 20-500 ms.