Replies: 4 comments 2 replies
-
|
We found out that a json can't be streamed that easily see this: symfony/symfony#60257 This is not an issue from Laravel. You can stream json lines if you want: https://marius-ciclistu.medium.com/streamed-json-lines-using-laravel-crud-wizard-free-cd650e272caa |
Beta Was this translation helpful? Give feedback.
-
|
would be different if this was jsonl |
Beta Was this translation helpful? Give feedback.
-
|
As far as I know json can be streamed yet partially incomplete. But this package should be able to read the stream: https://github.com/laravel/stream |
Beta Was this translation helpful? Give feedback.
-
|
The symfony implementation of StreamedJsonResponse is not streaming. We tested it. If you take the time to read the related issue we opened in their github you will see. If you can stream a json without using json_encode, then maybe it might work with that related laravel stream package. But for that you would want to echo hard coded parts of the json. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
12.34.0
PHP Version
8.4.13
Description
When streaming a
LazyCollectionas JSON, the response is not actually streamed — instead, the entire dataset is loaded into memory.I found that this happens because
LazyCollectionimplementsJsonSerializableviaEnumerable, causing it to be serialized in-memory rather than usingStreamedJsonResponse.Proposed Solution
LazyCollectionshould override thejsonSerializemethod fromEnumerableto use a more memory-efficient approach, same asStreamedJsonResponse::streamData.Steps To Reproduce
https://github.com/Sparclex/lazy-collection-json-memory-issue
Run the migrations an go to the start page. You'll find two links one with a lazy collection implementation and one with a generator function wrapped around the lazy collection (for which streaming works).
Beta Was this translation helpful? Give feedback.
All reactions