AmirAgha
AmirAgha

Reputation: 135

Can I do multiple MySQL work in Laravel?

I wrote a code like this (I use MySQL, PDO, InnoDB, Laravel4, localhost & MAC) :

$all_queue = Queue1::all()->toArray(); //count about 10000
ob_end_clean();

foreach($all_queue as $key=>$value) {

    $priceCreate=array(...);
    Price::create($priceCreate);
    Queue1::where('id',$value['id'])->delete();
}

This worked for me (65mg ram usage), but when it was working, other parts of my program(such as other tables) didn't work. I can't open my database on mysql even. My program and my sql wait and when process is completed ,they work.

I don't know what am i supposed to do. I think this is not for laravel and this is for my php or mysql configuration.

this is my php.ini and mysql config

Upvotes: 1

Views: 56

Answers (1)

maztch
maztch

Reputation: 1697

I assume

$all_foreach($all_queue as $key=>$value) {

Is

foreach($all_queue as $key=>$value) {

And that you have no errors (you have set debug true in your app config). Try to set no time limit for your script.

In your php.ini

max_execution_time = 3600  ;this is one hour, set to 0 to no limit

Or in code

set_time_limit(0)

And if it's a memory problem try to free memory and unset unused vars. I'ts a good practice in long scripts to free space.

    ...
}//end foreach loop
unset($all_queue); //no longer needed, so unset it to free memory

Upvotes: 2

Related Questions