doujiao1948 2014-03-21 08:53
浏览 79
已采纳

创建Tar文件时Php Stream到客户端

I have a special request for my PHP application.

Basically, an user can request a backup of his data as a TAR file. This archive contains a JSON file with the database informations (Profile, Various data, etc.) and a directory with all the files the user has upload since his registration.

So far, I've made the following code:

$phar = new PharData($output_filename);

$table_dump = self::dump_tables($customers);

$manifest = array();
$manifest['generation_time']  = time();
$manifest['manifest_version'] = self::DUMP_VERSION;

$phar->addFromString(self::MANIFEST_FILE, json_encode($manifest) );
$phar->addFromString(self::DATA_FILE, json_encode($table_dump) );

sql::select(file::sql_table, sql::true, file::sql_key);
$files_list = sql::fetch_all();
if ($files_list) foreach($files_list as $file_guid) {
  $file_path = file::forge_file_path($file_guid);
  if(is_file($file_path))
    $phar->addFile($file_path, basename($file_path));
}

return $output_filename;

It successfully returns a valid path with a valid TAR file that i can download. Today, the download is automatically started through a PHP Header but it takes ages to pack the TAR.

What I would like to know is: Is it possible to start downloading the file while it's being created ? (As a TAR file is made of collapsed files.)

Thanks for your help.

  • 写回答

1条回答 默认 最新

  • dongyou9721 2014-03-21 09:19
    关注

    I think if PHP is writing the file you would need another thread to read from that file. PHP does not support multithreading. You could probably use exec() or an extension like phtreads.

    I did not used it myself yet. But I read an article about it and it seems this could solve your problem.

    Good luck.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思