AWS 2.3.2 SDK for PHP を使用して、ストリーム ラッパーを使用して S3 から大きなファイル (~4g) をプルダウンしようとしています。メモリー。
参照は次のとおりです。
http://docs.aws.amazon.com/aws-sdk-php-2/guide/latest/service-s3.html#downloading-data
これが私のコードです:
public function download()
{
$client = S3Client::factory(array(
'key' => getenv('S3_KEY'),
'secret' => getenv('S3_SECRET')
));
$bucket = getenv('S3_BUCKET');
$client->registerStreamWrapper();
try {
error_log("calling download");
// Open a stream in read-only mode
if ($stream = fopen('s3://'.$bucket.'/tmp/'.$this->getOwner()->filename, 'r')) {
// While the stream is still open
if (($fp = @fopen($this->getOwner()->path . '/' . $this->getOwner()->filename, 'w')) !== false){
while (!feof($stream)) {
// Read 1024 bytes from the stream
fwrite($fp, fread($stream, 1024));
}
fclose($fp);
}
// Be sure to close the stream resource when you're done with it
fclose($stream);
}
ファイルはダウンロードされますが、Heroku から継続的にエラー メッセージが表示されます。
2013-08-22T19:57:59.537740+00:00 heroku[run.9336]: プロセス実行 mem=515M(100.6%) 2013-08-22T19:57:59.537972+00:00 heroku[run.9336]: エラーR14 (メモリ割り当て超過)
これは、これがまだ何らかの形でメモリにバッファリングされていると私に信じさせます。https://github.com/arnaud-lb/php-memory-profilerを使用しようとしましたが、Seg Fault が発生しました。
また、CURLOPT_FILEオプションを指定してcURLを使用してファイルをダウンロードして、ディスクに直接書き込もうとしましたが、まだメモリが不足しています。奇妙なことは、top
私のphpインスタンスによると、223mのメモリを使用しているため、許可されている512の半分でもない.
誰にもアイデアはありますか?これをphp 5.4.17 cliから実行してテストしています。