Reputation: 1146
I recently had to transfer my database to a remote server.
I used Postman to connect to PHP running on localhost to make the same requests. Here are the results,
MySQL on Localhost and Eloquent : ~30ms
MySQL on Remote Server and Eloquent : ~2.7 seconds
MySQL on Localhost and PHP: ~10ms
MySQL on Remote Server and PHP: ~850ms
The average ping from my computer to the the remote server ip is about 150ms.
Here is the PHP script I used,
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "select * from `online` where `online`.`id` = 1 limit 1";
$result = $conn->query($sql);
var_dump($result);
For eloquent, I just used Online::find(1)
.
I still haven't tried running eloquent on a server, but is this normal? Should I steer away from using eloquent if I am going to be using remote mysql databases on different servers?
EDIT:
I was changing some values, and when I removed the charset and collation value from eloquent config, the response time improved to 1.7s which is 1s faster.
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
Upvotes: 1
Views: 2449
Reputation: 6359
Eloquent vs MySQLi Native RAW Execution
Eloquent
is slower than Native MySQLi Execution
because it has a lot of built-in features. But, Eloquent
will make your code clean and easy. And providing better security.
Localhost vs Remote Host
When we talk about the Local Server
, The performance depends on your local environment. But, When you use Remote Host
, The performance will change because of the following reasons.
Best Practice / Architecture
When deploy an application to the production, Usually we don't keep database and application in same server. In production, Experts do following things to increase the database performance.
Upvotes: 2