我正在使用flysystem与IRON IO队列,我试图运行一个数据库查询,将采取约180万条记录,同时做5000个。这里是我用的50 + MB文件大小收到错误消息:phpleague flysystem读取和写入服务器上的大文件
PHP Fatal error: Allowed memory size of ########## bytes exhausted
下面是我想采取的步骤:
1)获取数据
2)打开它成CSV适当的字符串(即implode(',', $dataArray) . "rn")
3)从服务器获取的文件(在这种情况下,S3)
4)阅读文件的内容,并追加新〜应变g到它,并重新编写内容到S3文件
这里是一个简短的代码运行下来,我有:
public function fire($job, $data)
{
// First set the headers and write the initial file to server
$this->filesystem->write($this->filename, implode(',', $this->setHeaders($parameters)) . "rn", [
'visibility' => 'public',
'mimetype' => 'text/csv',
]);
// Loop to get new sets of data
$offset = 0;
while ($this->exportResult) {
$this->exportResult = $this->getData($parameters, $offset);
if ($this->exportResult) {
$this->writeToFile($this->exportResult);
$offset += 5000;
}
}
}
private function writeToFile($contentToBeAdded = '')
{
$content = $this->filesystem->read($this->filename);
// Append new data
$content .= $contentToBeAdded;
$this->filesystem->update($this->filename, $content, [
'visibility' => 'public'
]);
}
我猜想这是不是最有效的?我要走这些文档: PHPLeague Flysystem
如果任何人都可以指出我在一个更合适的方向,这将是太棒了!
2014-09-24
klye_g
+0
有什么办法将追加到使用Flysystem文件?否则,我不知道如何避免使用这么多的内存。 –
2014-09-24 15:24:49
+0
@andy不,它看起来不像。他们有一个流功能,但我认为这与您必须阅读该文件以更新其内容的方式相同。 –
2014-09-24 15:57:30
本文发布于:2024-02-02 19:09:40,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170687218145846.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |