Search code examples
mysqllaravellaravel-5eloquentlaravel-query-builder

How can fetching huge records using Laravel and MySQL?


I Need experts Suggestions and Solutions. We are developing job portal website here by handle around 1 million records. We are facing records fetching timeout errors. How can I handle those records using laravel and MySql?

We are trying to follow steps:

  1. Increase the PHP execution time
  2. MySql Indexing
  3. Paginations

Solution

  • You should be chunking results when working with large data sets. This allows you to process smaller loads, reduces memory consumption and allows you to return data to the User while the rest is being fetched/processing. See the laravel documentation on chunking:

    https://laravel.com/docs/5.5/eloquent#chunking-results

    To further speed things up you can leverage multithreading and spawn concurrent processes that each handle a chunk at a time. Symfony's Symfony\Component\Process\Process class makes this easy to do.

    https://symfony.com/doc/current/components/process.html