6 months ago

Fetch array from Import Source in Chunks

Posted 6 months ago by kshitizmittal
Excel::load(Input::file('import_file'), function ($reader) {
                foreach ($reader->toArray() as $row) {
                    Roster::updateOrCreate(['emp_id'=> $row['emp_id'],'month'=> $row['month'],'year'=> $row['year']],$row);
                    $month_name = $row['month'];
                    $wo_arr = explode(',',$row['week_off']);
                    $daily_roster_arr = [];
                    for($i=1;$i<=cal_days_in_month(CAL_GREGORIAN, date('m', strtotime($month_name)), $row['year']);$i++){
                        $date = date('Y-m-d', strtotime($i.' '.$row['month'].' '.$row['year']));
                        $day = date('l', strtotime($i.' '.$row['month'].' '.$row['year']));

                        $daily_roster_arr['emp_id'] = $row['emp_id'];
                        $daily_roster_arr['time_in'] = $row['roster_time_in'];
                        $daily_roster_arr['time_out'] = $row['roster_time_off'];
                        $daily_roster_arr['date'] = $date;
                        $daily_roster_arr['day'] = $day;
                        $daily_roster_arr['week_off'] = (in_array($day, $wo_arr) ? 'Yes' : NULL);
                        DailyRoster::updateOrCreate(['emp_id'=> $daily_roster_arr['emp_id'],'date'=> $daily_roster_arr['date']],$daily_roster_arr);

This is my import function, I am trying top import more than 50000 records so it is showing 500 server error in spite of increasing execution time in php.ini file.

How can I fetch rows from excel in chunks?

Using Maatwebsite import package.

Please sign in or create an account to participate in this conversation.