我使用两个php库来提供文件- unzip和dUnzip2
zip zip.lib
http://www.zend.com/codex.php?id=470&single=1
它们在10MB以下的文件上工作得很好,但对于10MB以上的文件,我必须将内存限制设置为256。对于超过25MB的文件,我将其设置为512。它看起来有点高...是吗?
我在一个专用的服务器上-4个CPU和16‘s内存-但我们也有很多流量和下载,所以我想知道这里。
发布于 2012-08-06 12:56:23
也许您正在使用php将整个文件加载到内存中,然后再将它们提供给用户?我使用了在http://www.php.net/manual/en/function.readfile.php (注释部分)找到的一个函数,该函数将文件分成几个部分,从而保持较低的内存。从那篇文章中复制(因为我的版本改变了):
<?php
function readfile_chunked ($filename,$type='array') {
$chunk_array=array();
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$handle = fopen($filename, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
switch($type)
{
case'array':
// Returns Lines Array like file()
$lines[] = fgets($handle, $chunksize);
break;
case'string':
// Returns Lines String like file_get_contents()
$lines = fread($handle, $chunksize);
break;
}
}
fclose($handle);
return $lines;
}
?>https://stackoverflow.com/questions/11822294
复制相似问题