0
過去幾天我一直在努力解決這個問題,所以也許有人可以幫我解決這個問題。我正在開發一個大型應用程序,它必須提取一個包含大約3-4GB CSV文件的〜200MB ZIP文件。PHP - 異步提取大型ZIP文件
爲此,我編寫了一個jQuery插件,用於在ZIP提取時向用戶顯示某些內容,並處理超時。但是一旦提取過程開始,Ajax就不能發送「完成了嗎?」請求到服務器,因爲他們也超時。所以我的問題是 - 是否有辦法異步啓動ZIP提取,然後檢查進度?
我建立的笨框架和ZIP解壓功能,這個應用程序是這樣的:
public function unpack_zip ($zip_file) {
// First we check the database to see if the extraction process has already started
$extracting_file = $this->db->select('value')->from('setting')->where(array('type' => 0, 'key' => 'tube_extractng'))->get()->result_array();
if (!!$extracting_file[0]['value']) return 'Already extracting!';
// Next we create a strimg containing path to the zip file.
$source_file = $this->install_assets_dir . 'zip' . DIRECTORY_SEPARATOR . $zip_file;
$zip = new ZipArchive;
if ($zip->open($source_file) === TRUE) {
// If the zip was open sucessfully we tell the database that extraction is in progress, this stays "true" until the process completes
$this->db->update('setting', array('value' => true), array('type' => 0, 'key' => 'tube_extractng'));
set_time_limit(600); // The timeout long enough to extract an extra large file
$zip->extractTo($this->install_assets_dir . 'csv' . DIRECTORY_SEPARATOR);
$zip->close();
rename($source_file, preg_replace('/\.zip$/', '.extracted$0', $source_file)); // Renaming the extracted zip by adding ".extracted" before the extension
$this->db->update('setting', array('value' => false), array('type' => 0, 'key' => 'tube_extractng')); // And, of course tell the database that the process is done.
return TRUE;
}
return FALSE;
}
的問題是 - 一旦這個過程開始的服務器沒有響應,直到提取完成。無響應的服務器=沒有迴應「你還在提取嗎?」 Ajax調用。
它必須是另一個並行請求來檢查是否存在提取的文件。 – Deadooshka
我正在做一個並行請求,但它沒有響應。 – Vorta