We could have some cases which should fetch large json for DB records.
On laravel, we can simple following as:
response->json(User::get()….)
But if the records are large, it will have a lot of ram on server.
Also if there are a lot of requests, it will be more problems.
So, we can solve following as:
- use laravel chunk ( please check official documentation for chunk )
- create a json file and append the records in chunk iterator.
- return the json file instead of returning to a large collection.