have you try
Eloquent::unguard();
YourTableModel::insert( $data );
Just tried, now it takes 592 seconds....still too much!
how long its take by using the cmd line ???
mysql -u root -p1234 your_database_name < code.sql
put this code at the top in the code.sql
file
SET @startTime = UNIX_TIMESTAMP();
and this at end of the file
SELECT CONCAT( UNIX_TIMESTAMP() - @startTime, ' seconds' ) AS ' ';
peppe@ub-R540:~/Desktop$ mysql --user=root --password=XXX db_test_insert < code.sql
1 seconds
peppe@ub-R540:~/Desktop$
11,177 record
how do you are measuring the laravel sql execution time code ??? you need to call DB::getQueryLog()
, there is property called time
for each query that has been executed
I measured the script execution time, using microtime() I run the script and I move on phpmyadmin to see what's happening, the insertions are very slow
The same script using mysqli takes ±25 seconds
Briefly, the script reads the .sql file, explodes every line (which one is an insert query), take che id, check if the id is present in the table, if is present change the insert query in an update query and execute the update, else insert the new row
Only for checking if an id is present in the table, using DB::find(id) - without executing the insert query - the script has an execution time of ±15 seconds
Solved, it was a problem of storage engine, changed from InnoDB to MyISAM
Now using:
mysqli->query( $query ): ± 5 seconds
model::create( $data ): ± 35 seconds
db::statement( $query ): ± 25 seconds
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community