我试图设置一个简单的模拟http响应作为PHP脚本。因此我有这样的代码:
<?php
$filename = "output.txt.gz";
$filesize = filesize($filename);
//ignore the next 3 lines
$handle = fopen($filename, "r");
$contents = fread($handle, $filesize);
fclose($handle);
header("HTTP/1.1 200 OK");
header("Content-Encoding: gzip");
header("Content-Type: text/xml;charset=UTF-8");
header('Content-Length: '.$filesize);
header("location: ".$filename);
?>
如果我用小数据(1mb)触发脚本,它工作得很好,但对于像80mb这样的巨大内容,它没有!
出了什么问题,如何解决?
不是最好的解决方案,但是尝试将这一行放在代码的开头
ini_set('memory_limit','512M');
编辑
似乎你有可能超时的问题,再加上这一行:
set_time_limit(0);
重要: set_time_limit(0)将设置执行时间为无限,不建议这样做,但看看它是否解决了您的问题,如果它尝试优化超时