【发布时间】:2015-01-08 00:04:34
【问题描述】:
我正在使用 PHP 的 Google App Engine 上运行应用程序。
我正在使用以下代码从 API 下载文件:
$context = [
"http" => [
"method" => "GET",
"header" => "Authorization: ".$token."\r\n",
"follow_location"=>1,
"timeout"=>600,
"ignore_errors"=>1
]
];
$context = stream_context_create($context);
$sourceFile = fopen($location,"r", false,$context) or die("no handle");
此代码之后是对另一个资源的块读取和写入(基本上我将文件存储在 Google 存储上)。
$destinationFile = fopen($filename,"w");
while ($buffer = fread($sourceFile, 1048576)) {
fwrite($destinationFile,$buffer);
}
此代码的问题在于,如果文件很小(大约低于 30 MB),它确实可以正常工作,但如果文件很大,则 fopen 会失败。我收到“无句柄”消息。
这有点奇怪,因为我明确避免使用 file_get_contents 将整个文件下载到内存中,我不明白为什么 fopen 会失败!
你能帮帮我吗?谢谢
【问题讨论】:
-
另请注意,如果在本地(而不是在 Google App Engine 上)执行此代码,即使在大文件上也能完美运行。所以肯定是App Engine的一些配置...
标签: php google-app-engine