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 not working and sometimes also throw "allowed memory size ... exhausted" #535

Open
jasonbigl opened this issue Dec 14, 2022 · 2 comments

Comments

@jasonbigl
Copy link

Make sure you read Issues Guideline and answer these questions before submitting your issue. Thanks!
(Any non-English issues will be closed immediately.)

  1. Please provide your PHP and Swoole version. (php -v and php --ri swoole)
PHP 7.4.21 (cli) (built: Jul 22 2021 02:54:54) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.8.12
Built => Oct  9 2022 10:32:04
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.1.1n  15 Mar 2022
dtls => enabled
http2 => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. Please provide your Laravel/Lumen version.

Laravel 8.83.13

  1. Which release version of this package are you using?

v2.12.1

  1. What did you do? If possible, provide a recipe for reproducing the error.

I want to provide customer a option to export large data from database, but when I tried streamdownload, the application only init the download, but never starting download it. Here is a reproduce code:

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Str;
use Illuminate\Support\LazyCollection;

class IndexController extends Controller
{
/**
     * Undocumented function
     *
     * @param Request $request
     * @return void
     */
    public function export(Request $request)
    {
        $collection = LazyCollection::times(100000, fn () => [
            'user_id' => mt_rand(10, 100),
            'name' => Str::random(mt_rand(10, 20)),
            'logged_in_at' => now()->toIsoString(),
        ]);

        return response()->streamDownload(function () use ($collection) {
            $output = fopen('php://output', 'w+');

            fputcsv($output, ['User ID', 'Name', 'Login Time']);

            $collection->each(fn ($row) => fputcsv($output, $row));

            fclose($output);
        }, 'file.csv');
    }
}
  1. What did you expect to see?

download large data by streaming without consuming all memory

  1. What did you see instead?

The browser only init the download, but never starting download content.

https://imgur.com/a/GvGzRng

@0utc0ntr0l2021
Copy link

yes that is happend with me not work

@szylmzs
Copy link

szylmzs commented Oct 24, 2023

happened with me when laravel handle some operation which needs more memory setting in php.ini

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

3 participants