Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8892527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:01:20+00:00 2026-06-14T23:01:20+00:00

I have a file a csv file (made as .txt) that I am currently

  • 0

I have a file a csv file (made as .txt) that I am currently parsing right now, but the file is about 350mb uncompressed. When it’s zipped, it shows in the zip file as 23mb. My system completely freezes when I try to parse the 350mb file. I store the lines in an array like this. The first row are the headings.

$fh = fopen($inputFile, 'r');
    $contents = fread($fh, filesize($inputFile)); // 5KB
fclose($fh);
//$contents = str_replace('"','',$contents);

$fileLines = explode("\n", $contents); // explode to make sure we are only using the first line.

Then I go through each line to insert it in a loop into mySQL. Since the file is about 350mb, would there be a way to parse it from the .zip file like .zip_filename.txt or would that even make a difference at all?

The file is too large to insert directly into mysql through the import method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:01:22+00:00Added an answer on June 14, 2026 at 11:01 pm

    Use the built in function fgetcsv:

    <?php
    $row = 1;
    if (($handle = fopen($inputFile, "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            $num = count($data);
            echo "<p> $num fields in line $row: <br /></p>\n";
            $row++;
            for ($c=0; $c < $num; $c++) {
                echo $data[$c] . "<br />\n";
            }
        }
        fclose($handle);
    }
    ?>
    

    Also use multi insert if possible. Instead of running multiple queries:

    insert into table (col1, col2) values("row1-col1", "row1-col2");
    insert into table (col1, col2) values("row2-col1", "row2-col2");
    

    Building one query like this is much quicker:

    insert into table (col1, col2) 
    values ("row1-col1", "row1-col2"),
           ("row2-col1", "row2-col2");
    

    By the way, you can also load a file directly into mysql:

    load data local infile 'file.csv' into table table_name fields terminated by ','
    enclosed by '"'
    lines terminated by '\n'
    (col1, col2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a java application that stores data from a .csv file to
I have a CSV-like text file that has about 1000 lines. Between each record
I have made a function in Scilab that saves data in a *.csv file,
I have .csv file that contain 2 columns delimited with , . file.csv word1,word2
I have a file that contains the following in a csv file; country,region,city,postalCode,metroCode,areaCode I
I have a CSV file that goes something like this: ['Name1', '', '', '',
I have a CSV file with 6 millions rows. Each line is made up
I have a CSV file. Each line is made up of the same format
Assume you have a data set as something like a CSV file that contains
I have CSV file and Macro in VBA. I want to open CSV file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.