Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streamDownload下载大文件总是内存超限 #425

Open
jasonbigl opened this issue Dec 13, 2022 · 0 comments
Open

streamDownload下载大文件总是内存超限 #425

jasonbigl opened this issue Dec 13, 2022 · 0 comments

Comments

@jasonbigl
Copy link

jasonbigl commented Dec 13, 2022

+---------------------------+---------+
| Component | Version |
+---------------------------+---------+
| PHP | 7.4.21 |
| Swoole | 4.8.12 |
| LaravelS | 3.7.31 |
| Laravel Framework [local] | 8.83.13 |
+---------------------------+---------+

重现代码如下。

这是为什么?laravel streamDownload是用来下载大文件的,怎么和laravels+swoole配合就回超过内存限制?找了大半天不知道原因在哪里

php配置的内存限制是128M,请问应该怎么解决呢?(除了修改内存限制)

<?php
namespace App\Http\Controllers;

use Illuminate\Support\Str;
use Illuminate\Support\Facades\Log;

class IndexController extends Controller
{
  public function export(Request $request){
    return response()->streamDownload(function () {
            $file = fopen('php://output', 'w+');

            $i=1;
            while ($i <= 1000000) {
                $data = Str::random(mt_rand(100, 200));
                fputcsv($file, [$data]);
                $i++;
            }

            Log::info(memory_get_usage() / 1024 / 1024);

            fclose($file);
        }, 'file.csv');
  }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant