I have this login sistem:
require_once "conexion.php";
class login extends conexion {
public function log_user($user,$pass)
{
$conexion = mysql_conexion();
$login = "SELECT user_name,user_pass,id FROM menssager_user WHERE user_name='$user' AND user_pass='$pass'";
$e = $conexion->prepare($login);
$e->execute();
$re = $e->fetch(PDO::FETCH_ASSOC);
if($user == $re["user_name"] && $pass == $re["user_pass"])
{
$this->is_online($re["id"]);
return $re["id"];
}
$conexion = null;
} }
And when i execute that code, it takes 1.3 seconds to find out if that user exists and I have just 2 username in the DB. Can someone tell me why so slow? Note: yesterday i upgrade to 5.4.7 and re-write the code again(for new features of that version).
Update:
And the database conexion:
class conexion{
public function mysql_conexion(){
$conexion_path = "mysql:dbname=menssager;host:127.0.0.1";
$root = "root";
$pass = "";
try{
$conectar = new PDO($conexion_path,$root,$pass);
$conectar->setAttribute(PDO::ATTR_EMULATE_PREPARES,false);
$conectar->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $error)
{
echo $conectar = $error->getMessage();
}
return $conectar;
}
}
While you are still measuring the connection vs execution times, I am going to hazard a guess at the answer. I think your connection time is what is causing the delays. Look at this similar question asked earlier. https://serverfault.com/questions/408550/connecting-to-mysql-from-php-is-extremely-slow
Turning off reverse DNS lookup might help you. Adding a link showing how you can turn it off: