[SOLVED] twenty second reponse time for a very simply PHP MySQL combination
Posted by: SimonT (---.lightspeed.stlsmo.sbcglobal.net)
Date: June 14, 2016 07:13AM

I've got a default installation of WAMP, I haven't made any optional changes to the configuration.

I have a very simple "application" which

- user fills in a login form and submits it
- PHP code gets user's password from DB
- hashs - SHA256 - the user's password input
- compares the hashed password and the hashed password from the DB and outputs a Correct or Not Correct message via echo

When I click the submit form it takes takes 20 seconds to get a response back.

I seem to remember seeing a post like this before but I can't find it.

The HTML/PHP involved is small, so I'm going to show it below. This works properly but takes forever. Also, yes, I've done no input sanitizing - I'm just learning to use MySQL from PHP. I will add the best security I can as I go along. These are just my first small steps:

HTML file with login form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[www.w3.org];
<html xmlns="[www.w3.org];

<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<p>Please Login</p>
<form method="post" action="[justblog];
<p><input name="userName" type="text" /></p>
<input name="password" type="text" />
<input name="Submit1" type="submit" value="submit" />
</form>
</body>
</html>


Login processing HTML/PHP file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[www.w3.org];
<html xmlns="[www.w3.org];
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<?php
$link = mysqli_connect("localhost", "root", "", "justblog" ) ;
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
else {
// Attempt select query execution
$sql = 'SELECT * FROM jb_users WHERE userName="' . $_POST['userName'] . '"';
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
$row = mysqli_fetch_array($result);
$hashed = hash('sha256', $_POST['password']);
if ($hashed == $row['password']) {
echo $row['userName'] . ' Password is Correct<br>';
}
else {
echo $row['userName'] . ' <b>Password is INCORRECT</b><br>';
}
// Close result set
mysqli_free_result($result);
}
else{
echo "No records matching your query were found.";
}
}
else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
}
mysqli_close($link);
?>
</body>
</html>


I just timed another try and it went 26 seconds.

Can anyone suggest any configuration changes that will make this bloody thing respond in a reasonable time - like a fraction of a second?



Edited 1 time(s). Last edit at 06/15/2016 12:55AM by SimonT.

Options: ReplyQuote
Re: twenty second reponse time for a very simply PHP MySQL combination
Posted by: SimonT (---.lightspeed.stlsmo.sbcglobal.net)
Date: June 14, 2016 07:15AM

I should have said I'm running WampServer Version 3.0.4 64bit

Options: ReplyQuote
Re: twenty second reponse time for a very simply PHP MySQL combination
Posted by: Otomatic (Moderator)
Date: June 14, 2016 10:01AM

Hi,

> $link = mysqli_connect("localhost", "root", "", "justblog" ) ;
With Windows, dont' use localhost as MySQL host, use 127.0.0.1

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: twenty second reponse time for a very simply PHP MySQL combination
Posted by: SimonT (---.lightspeed.stlsmo.sbcglobal.net)
Date: June 14, 2016 10:37PM

@ Otomatic,

I'll give that a try right now.........

WOW!!!!

If you blink, you miss it.

Thanks

Options: ReplyQuote
Re: twenty second reponse time for a very simply PHP MySQL combination
Posted by: SimonT (---.lightspeed.stlsmo.sbcglobal.net)
Date: June 14, 2016 10:53PM

How do I mark this as a solved?

Options: ReplyQuote


Sorry, only registered users may post in this forum.