lundi 27 mai 2019

How to fix "Laravel take a long time to run a simple mysql query"

I have a database and I wrote a restful api use Laravel Framework. I did a simple query to database through Eloquent and return a json data

$notification = \App\Notification::first();
return response()->json($notification,200);

I logged and this query take 4246ms to finish

sql = select * from `Notification` limit 1
time = 4246.21 ms

Beside I did this query in Sequel Pro and It took only 922 ms to finish

This is my mysql config

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8',
            'collation' => 'utf8_general_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
            'timezone'  => '+00:00'
        ]

I don't know how to reduce mysql execution time in Laravel

Anyone here can help me. Thanks in advance!!!



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2wjQluS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire