Я борюсь с этой проблемой в течение последних нескольких дней, поэтому, возможно, кто-то может мне помочь с этим. Я разрабатываю большое приложение, которое должно извлечь один ZIP-файл ~ 200 МБ, содержащий около 3-4 ГБ файлов CSV.
Для этого я написал плагин jQuery, который должен был показывать что-то пользователю во время распаковки ZIP и обрабатывать тайм-ауты. Но как только процесс извлечения начался, Ajax не может отправить сообщение «он еще не завершен?» запросы к серверу, так как они также истекают по тайм-ауту. Итак, мой вопрос: есть ли способ запустить извлечение ZIP асинхронно, а затем проверить ход?
Я создаю это приложение на платформе CodeIgniter, и функция извлечения 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;
}
Проблема в том, что после запуска процесса сервер не отвечает до тех пор, пока извлечение не будет завершено. Сервер не отвечает = нет ответов на вопрос "Вы все еще извлекаете?" Аякс звонит.