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 9298325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:17:44+00:00 2026-06-18T22:17:44+00:00

My current code: $fileone= fopen(fileone.sql, r); //opens file fileone.sql $fileonewrite = fopen(fileone.rdf, w); //this

  • 0

My current code:

$fileone= fopen("fileone.sql", "r"); //opens file fileone.sql
$fileonewrite = fopen("fileone.rdf", "w"); //this is the file to write to

$fileNum=1;
$i=0;
while (!feof($fileone) ) { //feof = while not end of file


    if ($contents = fread($fileonewrite ,53687091200));  //if file is more than 50gb, write to new file (below) .. this doesnt seem to work properly
    {    file_put_contents('fileone'.$fileNum.'.rdf',$contents);
    $fileNum++; 
    }

    $fileoneRow[] = fgets($fileone);  //fgets gets line
    $fileoneParts = explode("\t", $fileoneRow[$i]); //explode using tab delimiter 



    fwrite( " lots of stuff" );
     unset($fileoneParts);
    }
    fclose($fileonetype);   
    fclose($fileonewrite);

Im reading lots of data and outputting even more, the file created easily gets upto >200GB. This causes a memory problem. So what i would like to do, is when the file being written, e.g, fileone.rdf, gets to 50gb, i want to start writing to filetwo.
My code atm, doesnt work quite well as it seems to output thousands of empty files.

Thanks for reading my query, any help, as always is much appreciated.

  • 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-18T22:17:45+00:00Added an answer on June 18, 2026 at 10:17 pm
    if ($contents = fread($fileonewrite ,53687091200));  //if file is more than 50gb, write  to new file (below) .. this doesnt seem to work properly
                                                      ^----BUG BUG BUG
    {    file_put_contents('fileone'.$fileNum.'.rdf',$contents);
    $fileNum++; 
    }
    

    That ; terminates the if() statement there, so the code inside the {} is NOT part of if(); If the fread returns no data (eof), you’d still be writing an empty $contents out of the file, regardless of how the if() test came out.

    reading 50gigs of data in one go is simply insane. Why not something more along these lines:

    $in = fopen('input');
    $out = fopen('output');
    $read = 0;
    while($data = fread($fh, 1024*1024)) { // read in 1meg chunks 
        fwrite($out, $data);
        $read += strlen($data);
        if ($read > 50gig) {
            fclose($out);
            $out = fopen('new file goes here');
            $read = 0;
        }
    }
    

    that’ll do the copying in 1meg chunks, which would place FAR FAR FAR less pressure on system memory, and then swap to a new file whenever you have finally reached 50gig copied.

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

Sidebar

Related Questions

This is my current code: $directory = polls/; $dir = opendir($directory); while (($file =
This is my current code of the class Score in the Score.h file:- class
current code (not working): /^script\s*type=\text\/javascript/i.test(tagName)
My current code uploads image successfully but still it does not show Toast message
My current code is this $swift = email::connect(); $swift->setSubject('hello') ->setFrom(array('alex@example.com.au' => 'Alex')) ->setTo(array('alex@example.com.au' =>
Here is my current code: $files = glob(*.jpg); This works fine. However, I am
My current code is this: int volume = Alert.getVolume(); // reads 100 Alert.setVolume(0); It
Here is my current code: $sql = SELECT * FROM user_posts; $result = mysql_query($sql);
Current Code Hi I have a function like this: jj::[Int]->[Int] jj xs = [x|x<-xs,x
Current code: short s; s = short.Parse(this.txtFields3.Text); I've gone through with debugging, and can

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.