我有一个大的压缩文件(~15Gb压缩,~88未压缩),我需要将内容“爆炸”到大量文件。例如,如果我阅读以下行:
foo property.content "I'm the content of the string."
我需要创建一个名为foo.db
的文件并存储在其中:
property.content "I'm the content of the string."
我成功了。但我有表演问题。我想也许是因为文件量很大。 (~30k文件在60秒内创建)但我不确定。这就是我在这里的原因。
我的代码正在读取每个1048576字节(带有gzread
的gz文件),并对数组中的内容进行排序,以便按文件一次性写入所有内容。然后,我做了一个foreach循环来读取我的缓存内容,打开特定文件并写入。例如,如果我的缓存看起来像这样:
$cache = array(
"file_one" => "property.content \"I'm the content of the string.\"
property.foo \"I'm the content of another string.\"",
"file_two" => "property.foobar \"I'm the content of the another string.\"",
"file_three" => ...
);
循环使这个:
foreach ($cache as $file => $content) {
$filesrc = $file . ".db";
$fp = fopen($filesrc,"a");
fwrite($fp,$content."\n");
fclose($fp);
}
使用这种方法,我读取〜65Mb并在60秒内写入~31k文件。 如果我读取一个文件中的所有内容,我在60秒内写了~220Mb。
要提高性能并创建小文件,还有什么可做的?
我在PHP 5.5.1
上使用Apache 2.4.6
与Windows
CLI
,我正在使用{{1}}此脚本。
编辑:这是一个日志,用于获取每个循环的时间配置文件,用于131072个字节的数据:http://pastebin.com/uRPFfywY