Jump to content

max file size with file() ?


aebstract

Recommended Posts

Okay, this script:

<?php
$textData = file('array.txt');
echo "hello";
?>

 

hello is echo'd to the browser, no problems. If I change array.txt to array2.txt, it gives a white page and doesn't seem to even try to do anything.

array.txt is just under 1MB

array2.txt is just over 71MBs

 

Is there a limit on file size that can be opened? Cause I don't think it's hitting something inside and stopping, it seems to not even be attempting to look inside the file. Any other information needed for this problem?

Link to comment
Share on other sites

Of course there are limits, such as the amount of available memory.

 

You should be developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON so that php will help you by reporting and displaying all the errors it detects.

Link to comment
Share on other sites

My first piece of advice would be to turn on error reporting and/or check your php error logs. That usually reveals 99.9% of errors and should give you a better idea of why this isn't working.

 

71mb isn't all that big so can't see why it wouldn't work when you open that as oppose to your smaller file. There could be a parse error but it's doubtful. I don't think anything within the file could cause a parse error.

 

Get those errors and I'm sure we'd be able to help more.

Link to comment
Share on other sites

Sorry for not running that, which was completely stupid:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 75023834 bytes) in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 8

 

Is this something I can change or do I have to have my host change it?

Link to comment
Share on other sites

A far more useful solution would be to go through the file (often line-by-line) so as to only load a small portion of it into memory at any one time.  Unless there is some particular need to load 71 MB into memory every time the script is executed, I would advise against it.  I'd also echo the others' suggestion of enabling and displaying all errors during development.

Link to comment
Share on other sites

A far more useful solution would be to go through the file (often line-by-line) so as to only load a small portion of it into memory at any one time.  Unless there is some particular need to load 71 MB into memory every time the script is executed, I would advise against it.  I'd also echo the others' suggestion of enabling and displaying all errors during development.

 

I placed this at the top:

error_reporting(E_ALL);
ini_set("display_errors", 1);

 

but, with the .htaccess fix I mentioned above, I'm not getting an error just white space. I could do it one line at a time, but not too sure where to start as to write that, as right now I have a little function to do some array work so I can loop through every value and insert it in to the database. This is going to be a one time access deal, then it will be trashed and never ran again.

Link to comment
Share on other sites

Okay, I have my memory_limit set to 100M now, I am getting now errors but am still getting a blank white page. I have an echo statement ABOVE my file() and it isn't getting displayed either. Could something in the file be causing it to do this? If so, what would trigger such an event? Wouldn't I still get information up until the point that it causes error? The smaller file still works, the larger one is just blanking out.

Link to comment
Share on other sites

I got an email from my host and he said this is the error that was being displayed:

[sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice:  Undefined offset:  0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 48
[sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice:  Undefined offset:  0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 49
[sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice:  Undefined offset:  0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 50
[sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice:  Undefined offset:  0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 51
[sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice:  Undefined offset:  0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 52
[sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice:  Undefined offset:  0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 53
[sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice:  Undefined offset:  0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 54
[sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice:  Undefined offset:  0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 55
[sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice:  Undefined offset:  0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 56
[sat Mar 06 12:03:07 2010] [error] [client 12.248.157.94] PHP Notice:  Undefined offset:  0 in /var/www/vhosts/outlawracing.com/httpdocs/insert.php on line 57

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.