# Importing large amounts of CSV data into a web application

> Import large CSV files into a web application without timeouts by preparing the file, raising limits and importing in batches.

Source: https://helpcenter.ruachost.com/apps/guides/importing-large-amounts-of-csv-data-into-a-web-application/

Many web applications allow administrators to import data from **CSV (Comma‑Separated Values)** files. This is useful for bulk uploading records such as users, products, or transactions. On **ruachost.com**, you can safely import large CSV datasets into your web applications by following best practices.

## Why Import CSV Data?

- Efficiently migrate data from legacy systems.
- Bulk upload thousands of records at once.
- Save time compared to manual entry.
- Ensure consistency across applications.

## Steps to Import Large CSV Files

1. **Prepare Your CSV File.**

   - Ensure the file is properly formatted with consistent delimiters (commas or semicolons).
   - Include headers that match the database fields in your web application.
   - Remove unnecessary blank rows or columns.
2. **Check File Size Limits.**

   - Most hosting accounts limit file uploads (e.g., 2MB–50MB).
   - For larger files, split the CSV into smaller chunks or increase PHP upload limits in `php.ini`:

     ```
     upload_max_filesize = 128M
     post_max_size = 128M
     memory_limit = 256M
     ```
3. **Use the Application’s Import Tool.**

   - Many CMS/eCommerce platforms (WordPress, PrestaShop, CS‑Cart, etc.) include built‑in CSV importers.
   - Navigate to the **Admin Dashboard → Tools → Import** section.
   - Select your CSV file and map columns to database fields.
4. **Validate Data Before Import.**

   - Run a test import with a small sample file.
   - Check for errors such as missing fields, invalid characters, or duplicate entries.
5. **Optimize for Large Imports.**

   - Use **batch processing** to import data in smaller sets.
   - Disable unnecessary plugins or modules during import to reduce memory usage.
   - Consider using **command‑line import scripts** for very large files:

     ```bash
     php artisan import:csv users.csv
     ```

     *(Laravel example — adjust for your framework.)*
6. **Monitor the Import Process.**

   - Watch for timeout errors.
   - Enable logging to capture skipped or failed records.
   - If supported, use **background jobs** or **cron tasks** to handle imports asynchronously.
7. **Verify Imported Data.**

   - After import, check the database tables or application dashboard.
   - Confirm that all records were imported correctly.
   - Run reports to validate totals and consistency.

> **Note:**
- Large CSV imports may require adjusting server limits on **ruachost.com**.
- Always back up your database before running bulk imports.
- Consider using **queue workers** or **API‑based imports** for very large datasets.
