【发布时间】:2021-04-13 13:34:04
【问题描述】:
我有一个 Laravel 应用程序,其基础数据库具有长序列。我想为用户提供以 JSON 格式下载数据库的机会。为此,我首先获取记录,然后将它们转换为 JSON 格式并写入文件。 但是,当我将应用程序移至生产服务器时,它给了我
You don't have permission to access /saveJson on this server.
从日志中,是错误消息:
[2021-01-07 19:08:50] local.ERROR: Allowed memory size of 1887436800 bytes exhausted (tried to allocate 675803754 bytes) {"userId":1,"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 1): Allowed memory size of 1887436800 bytes exhausted (tried to allocate 675803754 bytes) at /home/xxx/vendor/league/flysystem/src/Util/MimeType.php:205)
[stacktrace]
服务器中的memory_limit已经设置为-1,设置后重启。
代码的相关部分:
DB::connection()->disableQueryLog();
$large_db = Model::with('regions', 'genes.gene_models.aro_categories')
->where('curated', '<>', 4)
->get();
$db_JSON = $large_db->toJSON();
Storage::disk('public')->put("database_$date.json", $db_JSON);
DB::connection()->enableQueryLog();
根据 MySQL,整个数据库大约 170M,根据 meminfo,服务器有 1962MB 内存,所以我不完全明白为什么它不能加载记录 - 虽然因为数据库要更新,所以我想创建在某种程度上它也不会因为类似的原因而崩溃。
有没有更聪明的方法在不超过内存限制的情况下导出数据库?某种缓冲?
感谢您的任何建议!
【问题讨论】:
标签: database laravel memory memory-limit