Well, you're not comparing like with like - the framework needs to boot, handle the request, build the query, instantiate the model instances and return a response. Try to seek out where the time is being spent by installing laravel-debugbar which will give you at least some rudimentary timings.
Nov 2, 2018
5
Level 8
Eloquent needs much time than phpmyadmin sql query
hello , first I added to mysql ST_Distance_Sphere() function witch calculate the distance between two coordinates (lat,lon) I created one controller to return the result as json response :
public function index( $from_location)
{
$response = station::select('id','name','label','address','longitude','latitude')
->whereRaw('ST_Distance_Sphere( POINT(latitude, longitude), POINT( '.$from_location.') ) < 1000 ')
->take(50)
->get();
return response()->json($response);
...
this controller load in 5.5 seconds but when I execute it from phpMyAdmin it needs only 0.05 second!!!
Showing rows 0 - 24 (25 total, Query took 0.0500 seconds.)
select `id`, `name`, `label`, `address`, `longitude`, `latitude` from `stations` where ST_Distance_Sphere( POINT(latitude, longitude), POINT( 50.9130988,4.4302298) ) < 1000 limit 50
how to minimize the response 's time ? thanks
Please or to participate in this conversation.