laravel Maximum execution time of 60 seconds exceeded —

  database, eloquent, laravel

hello guys so I am doing a laravel project ( new to laravel ).
i am supposed to to calculation from other tables and save the results in another OUTPUT table.
I have 8 calculation in total in each line and up to 3k lines to fill.
The problem that I get the ma execution time error 60 sec even if a change it in laravel and php.ini.
each function called is just calling a select where and sum I’ve decided to divide them for better org.
My question is is there a better way to process the data and minimize to exc time if you can help .

public function calcul($week)
    {   $test = Output::where('week',$week)->Limit(1);
        if($test->first()){
            return self::afficher($week);

        }
        else{
            
            DB::table('article')->orderBy('material')->chunk(100, function ($stocks){
           
            foreach ($stocks as $stock) {
                $id = $stock->material;
                $safe_stock=self::safe_stock($id);
                $past_need=self::PassedNeeds($id) - self::NeedsInTwoWeeks($id);
                $two_week_need=self::NeedsInTwoWeeks($id);
                $stock_=self::stock($id);
                $bdl=self::bdl($id);
                $sm=self::sm($id);
                $package=self::package($id);
               
                $store_1=self::store_1($id);
                $store_2=self::store_2($id);
                $store_3=self::store_3($id);
                Output::create([
                    'material' => $id,'safe_stock'=>$safe_stock,'past_need'=>$past_need,'two_week_need'=>$two_week_need,
                    'stock'=>$stock_,'bdl'=>$bdl,'sm'=>$sm,'package'=>$package,
                    'store_1'=>$store_1,'store_2'=>$store_2,'store_3'=>$store_3
                ]);
            }
            });
          
            return self::index();
           
            }
    }

Source: Laravel

Leave a Reply