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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:11:28+00:00 2026-05-10T16:11:28+00:00

fopen is failing when I try to read in a very moderately sized file

  • 0

fopen is failing when I try to read in a very moderately sized file in PHP. A 6 meg file makes it choke, though smaller files around 100k are just fine. i’ve read that it is sometimes necessary to recompile PHP with the -D_FILE_OFFSET_BITS=64 flag in order to read files over 20 gigs or something ridiculous, but shouldn’t I have no problems with a 6 meg file? Eventually we’ll want to read in files that are around 100 megs, and it would be nice be able to open them and then read through them line by line with fgets as I’m able to do with smaller files.

What are your tricks/solutions for reading and doing operations on very large files in PHP?

Update: Here’s an example of a simple codeblock that fails on my 6 meg file – PHP doesn’t seem to throw an error, it just returns false. Maybe I’m doing something extremely dumb?

$rawfile = 'mediumfile.csv';  if($file = fopen($rawfile, 'r')){     fclose($file); } else {   echo 'fail!'; } 

Another update: Thanks all for your help, it did turn out to be something incredibly dumb – a permissions issue. My small file inexplicably had read permissions when the larger file didn’t. Doh!

  • 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. 2026-05-10T16:11:28+00:00Added an answer on May 10, 2026 at 4:11 pm

    Are you sure that it’s fopen that’s failing and not your script’s timeout setting? The default is usually around 30 seconds or so, and if your file is taking longer than that to read in, it may be tripping that up.

    Another thing to consider may be the memory limit on your script – reading the file into an array may trip over this, so check your error log for memory warnings.

    If neither of the above are your problem, you might look into using fgets to read the file in line-by-line, processing as you go.

    $handle = fopen('/tmp/uploadfile.txt', 'r') or die('Couldn't get handle'); if ($handle) {     while (!feof($handle)) {         $buffer = fgets($handle, 4096);         // Process buffer here..     }     fclose($handle); } 

    Edit

    PHP doesn’t seem to throw an error, it just returns false.

    Is the path to $rawfile correct relative to where the script is running? Perhaps try setting an absolute path here for the filename.

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

Sidebar

Related Questions

Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);
Is there way that I can read the file from remote server using fopen
I am using fopen to read from a shared location if a files exists
I'm currently using fopen to write/read binary files. With small files all is fines.
am creating a .xls file using PHP fopen write and append the contents to
PHP's fopen lets you fopen() http locations as file streams. But you can't fseek()
The iPhone SDK docs claim fopen() is a supported method of file access but
It seems if I do something like $file = fopen($filepath, w); $CR = curl_init();
Is there a standard way to do an fopen with a Unicode string file
This is the code: unsigned int number; FILE* urandom = fopen(/dev/urandom, r); if (urandom)

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.