Welcome Guest, Not a member yet? Register   Sign In
[ASK-help] Multiple Insert data get 504 gateway timeout
#1

i have this code for multiple insert data and check data before insert,
example i have 400 row data, and when i try to run this script


PHP Code:
//get data tenant from tipe utilitas
            
$tenant $this->standmeter_model->get_data_meter($idunit$bulk_tenant$kode_ruang);
            
//$total = $this->standmeter_model->count_get_data_meter($idunit, $bulk_tenant, $kode_ruang);

            
$data_save = array();

            foreach (
$tenant as $row => $value
            {
                
                if(
$this->master_model->cek_yes_or_no('tr_meter_listrik', array('idunit'=>$idunit'idruang'=>$value['idruang'], 'substr(periode,1,7)'=>substr($periode,0,7))) === FALSE)
                {
                    
//get last standmeter
                    
$data_meter $this->master_model->get_by_id_select_where_array('tr_meter_listrik''meter_akhir', array('idunit'=>$idunit,'idruang'=>$value['idruang'], 'periode' => $periode_sebelumnya))->row_array();

                    
//get data from ruang
                    
if(empty($data_meter['meter_akhir']))
                    {
                        
$ruang $this->master_model->get_by_id_select_where_array('ms_ruang''meteran_'.$label.'_akhir', array('idruang'=>$value['idruang'], 'idunit'=>$idunit))->row_array();
                        
$meter_akhir $ruang['meteran_'.$label.'_akhir'];
                    }
                    else
                    {
                        
$meter_akhir $data_meter['meter_akhir'];
                    }

                    
$data_save[] = array(
                        
'id_meter' => 'EL'.$row.'_'.$idunit.'_'.now(),
                        
'idtenant' => $value['idtenant'],
                        
'idruang' => $value['idruang'],
                        
'idunit' => $idunit,
                        
'kode_ruang' => $value['kode_ruang'],
                        
'periode' => $periode,
                        
'tgl_awal' => $tgl_awal,
                        
'tgl_akhir' => $tgl_akhir,
                        
'meter_awal' => $data_meter,
                        
'faktor_meter' => '1',
                        
'created_at' => date('Y-m-d H:i:s')
                        );
                }    
            }

            
$this->db->insert_batch('tr_meter_listrik'$data_save); 
 

when the proses, the data can insert to DB but the browser/application get "504 Gateway Time-out";

[Image: d8210a11c97b4365b30004e777722367.png]
how i can optimize the application to be fast prosess and not get 504 error, thanks
Reply
#2

504 Gatetimeout is a HTTP Error not a database error.
The database takes too long to collect your data.
You probably have to increase max_execution_time in your php.ini

Or you can try the CI database reconnect.

PHP Code:
$this->db->reconnect(); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(01-24-2017, 05:45 AM)InsiteFX Wrote: 504 Gatetimeout is a HTTP Error not a database error.
The database takes too long to collect your data.
You probably have to increase max_execution_time in your php.ini

Or you can try the CI database reconnect.

PHP Code:
$this->db->reconnect(); 

i try to change max_execution_time ini php.ini, still not working. still get 504 and the process still to long,
Reply
#4

A couple other things you can try:

Code:
PhpMyAdmin - phpMyAdmin\config.inc.php

$ Cfg ['ExecTimeLimit'] = 0;


MySQL - command prompt

mysql --user=username --password=password dbname < dump.sql
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

Your making too many queries in loops. Query all the data in a single statement, validate or format it in PHP, then insert.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB