I was developing a Laravel application in LAMP setup at my local machine( my laptop).
For testing purpose, I tried to use the mysql service of Aws RDS
instead my local mysql server
. Found that, an API call which have only one db call with no join (query: show tables) - takes on average 12s. This is ridiculous. When I am using local mysql server, it is around than 600ms. Until now, PDO::ATTR_PERSISTANT was not enabled.
Logging in Illuminate\Database\Connectors\Connector.php
[ inside createConnection()
method ], I found that, this method is called for each request. This is for both mysql server.
Then, I set PDO::ATTR_PERSISTANT
to true
. But response time's are similar.
After looking a more closer, found this in the same file:
/**
* Create a new PDO connection instance.
*
* @param string $dsn
* @param string $username
* @param string $password
* @param array $options
* @return \PDO
*/
protected function createPdoConnection($dsn, $username, $password, $options)
{
if (class_exists(PDOConnection::class) && ! $this->isPersistentConnection($options)) {
return new PDOConnection($dsn, $username, $password, $options);
}
return new PDO($dsn, $username, $password, $options);
}
And PDOConnection
- which extends PDO
, that is used when persistent is false - constructor is:
public function __construct($dsn, $user = null, $password = null, array $options = null)
{
try {
parent::__construct($dsn, $user, $password, $options);
$this->setAttribute(PDO::ATTR_STATEMENT_CLASS, ['Doctrine\DBAL\Driver\PDOStatement', []]);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
}
It seems, setting PDO::ATTR_PERSISTANT
to true
has no effect. This made me confused.
- How actually persistent database connection plays in Laravel?
- What was the reason behind long response time (with mysql service of
Aws RDS
) ?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2G1cAxm
via IFTTT
Aucun commentaire:
Enregistrer un commentaire