Answer the question
In order to leave comments, you need to log in
How to reduce memory usage when processing a large XML file?
This code generates an SQL query from an XML file.
$data=file_get_contents($uploads.$filename);
$xmlf=new SimpleXMLElement($data);
$g_table='SET NAMES "utf8";';
$g_table.='INSERT INTO groups (group_id,group_name) VALUES ';
foreach ($xmlf->gr as $group) {
$g_table.='('.$group['group_id'].','.$group['group_name'].'),';
}
$g_table=rtrim($g_table,',');
$g_table.='ON DUPLICATE KEY UPDATE group_id=VALUES(group_id),group_name=VALUES(group_name)';
$g_table_file=fopen('sqlfiles/groups.sql','w');
$file_bool['g_table']['file']=fwrite($g_table_file,$g_table);
fclose($g_table_file);
$file_bool['g_table']['query']=$this->query($g_table);
unset($g_table);
unset($g_table_file);
unset($xmlf->gr);
<Main>
<!--- ~200 строк -->
<gr group_id="101" group_dependence="0" group_name="Группа такая-то" group_description="''"/>
<!--- ~11000 строк -->
<gp group_id="1897" ppl_name="Иванов Иван Иваныч" tgl="5"/>
<!--- Еще ~30к строк с различными именами и параметрами -->
</Main>
Answer the question
In order to leave comments, you need to log in
However, if it is split and executed in one script, it may happen that there is not enough memory.
However, if it is split and executed in one script, it may happen that there is not enough memory.
Lord, please describe specifically the task and input data) + solution code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question