I do something like you.
I have do download from web-service zip archive with 3 xml large file compressed. I do this: on init i set :
ini_set('max_execution_time', 1000); //600 seconds
ini_set('mysql.connect_timeout', 1000); //run large sql
ini_set('default_socket_timeout', 1000);
I download the zip file to temp folder:
/**
* Metoda care scrie arhiva pe hardisc
* @param $string textul de scris in fisierul zip
* @return string Calea catre fisiser
*/
private function write_to_file($string)
{
$base = $this->tmpPath;
$date_folder = $base.date('Y_m').DIRECTORY_SEPARATOR.date('d');
if(!file_exists($date_folder))
{
mkdir($date_folder, 0777, TRUE);
}
$file = $date_folder.DIRECTORY_SEPARATOR.'products_'.date("Y_m_d_H_i").'.zip';
// This uses less memory than file_put_contents
$f = fopen($file, 'w');
fwrite($f, $string);
fclose($f);
return $file;
}
After this i extract the xml files from the zip to temp folder:
public function dezarhiveaza($file)
{
$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
$zip->extractTo($this->tmpPath);
$zip->close();
$this->write_log('extract success');
} else {
$this->write_log('error ');
}
}
And next i extract the list of products from the XML and i make the insert MySQL query with 1000 rows:
private function deserializeazaForme()
{
$formePath=$this->tmpPath.
"data".DIRECTORY_SEPARATOR.'forme.xml';
$xml = simplexml_load_file($formePath);
$forme = $xml->xpath('//Table');
if($forme)
{
$strFormeInsertFirst="INSERT INTO `forme` (`id`, `denumire`) VALUES ";
$strFormeInsert=$strFormeInsertFirst;
foreach ($forme as $key=>$forma) {
$strFormeInsert .= "(".$forma->id.",'".$forma->denumire."),";
if($key%1000==0 && $key >0){
$strFormeInsert = rtrim($strFormeInsert, ",") ;
$strFormeInsert .=";";
$this->runQuery($strFormeInsert);
$strFormeInsert=$strFormeInsertFirst;
}
}
$strFormeInsert = rtrim($strFormeInsert, ",") ;
$strFormeInsert .=";";
$this->runQuery($strFormeInsert);
}
}