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

  • Home
  • SEARCH
  • 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 7870375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:36:12+00:00 2026-06-03T01:36:12+00:00

I have a big csv file ( about 30M ), that I want to

  • 0

I have a big csv file ( about 30M ), that I want to read using my php program and convert it to another format and save it as different small files . When I am using the traditional fopen , fwrite methods I am getting an error that says Fatal error: Allowed memory size of 134217728 bytes exhausted . I am aware that I can set the memory limit in php.ini but is there any way that I can read the file as stream so that it wont create much memory overhead ? May be something like StreamReader classes in java ?

  • 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-03T01:36:15+00:00Added an answer on June 3, 2026 at 1:36 am

    You could just read the file one line at a time with fgets(), provided you are reassigning your variable each time through (and not storing the lines in an array or something, where they would remain in memory).

    One way, with a ~65 MB file:

    // load the whole thing
    $file = file_get_contents('hugefile.txt');
    echo memory_get_peak_usage() / 1024 / 1024, ' MB';
    // prints '66.153938293457 MB'
    

    Second way:

    // load only one line at a time
    $fh = fopen('hugefile.txt', 'r');
    while ($line = fgets($fh)) {}
    echo memory_get_peak_usage() / 1024 / 1024, ' MB';
    // prints '0.62477111816406 MB'
    

    Also, if you want to rearrange the data in a different format, you could parse each line as CSV as you go using fgetcsv() instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written a big sql script that creates a CSV file. I want to
I have a CSV file which is about 1GB big and contains about 50million
I want to convert a big csv file from gb2312 encoding to UTF-8 encoding.
I have a big csv files with the following format: CSV FILE 1 id,
I have an quite big CSv File I want to have in Google Maps
I have a big string (let's call it a CSV file, though it isn't
I have big trouble with file uploads with php. My own tests are successful
I have a big csv file with datetime and value recorded every 10 seconds.
I have a big csv file which lists connections between nodes in a graph.
I have quite a big network in a CSV file. It containt 450k nodes

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.